I have the following data:
Date Code
2014-08-01 A
2014-08-02 A
2014-08-03 A
2014-08-04 A
2014-08-05 A
2014-08-06 A
2014-08-07 A
2014-08-08 XXXX
2014-08-09 XXXX
2014-08-10 BB
2014-08-11 CCC
2014-08-12 CCC
2014-08-13 CCC
2014-08-14 CCC
2014-08-15 CCC
2014-08-16 CCC
2014-08-17 CCC
2014-08-18 XXXX
2014-08-19 XXXX
2014-08-20 XXXX
2014-08-21 XXXX
2014-08-22 XXXX
2014-08-23 XXXX
2014-08-24 XXXX
2014-08-25 XXXX
2014-08-26 XXXX
2014-08-27 XXXX
2014-08-28 XXXX
2014-08-29 XXXX
2014-08-30 XXXX
2014-08-31 XXXX
I want to group the data with codes but also with date ranges so that the output becomes:
Min Date Max Date Code
2014-08-01 2014-08-07 A
2014-08-08 2014-08-09 XXXX
2014-08-10 2014-08-10 BB
2014-08-11 2014-08-17 CCC
2014-08-18 2014-08-31 XXXX
I have thought about it but cannot think of how to group this data using SQL. Any ideas? Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…