的不同列的SQL查詢我有不同的記錄的列開始日期和結束日期。 如果我按開始日期的升序對記錄進行排序。 ,並希望連續查找一行的開始日期和前一行的結束日期之間的差異。用於獲取差異高炮不同行
e.g.
Table: Data
------------
Date1 Date2
13-DEC-2011 15-DEC-2011
18-DEC-2011 16-DEC-2011
21-DEC-2011 24-DEC-2011
多了一個查詢,如果我有一個第三列 說ID,我想區別通過分組這些ID的 如
ID Date1 Date2
1 13-DEC-2011 15-DEC-2011
1 18-DEC-2011 16-DEC-2011
2 21-DEC-2011 24-DEC-2011
2 25-JAN-2012 25-FEB-2012
2 29-FEB-2012 25-MAR-2012
and I need :
ID INTERVAL FREE
1 15 DEC to 18 DEC
2 24dec to 25 jan;25 feb to 29 feb
看看這個答案我的。可能有幫助。 http://stackoverflow.com/questions/11262260/finding-free-blocks-of-time-in-mysql-and-php –