SQL Query Creating Start and End Dates

后端 未结 3 1910
无人共我
无人共我 2021-01-14 11:18

Alright, let\'s say I have a table that looks like this:

 ID   | DATE
 2  | 2010-08-12
 2  | 2010-08-16 
 2  | 2010-08-17 
 2  | 2010-12-21 
 2  | 2010-12-22         


        
3条回答
  •  灰色年华
    2021-01-14 11:47

    if you have serialize id like ( 1,2,3,4,5,..) then you can get the above with this query with 1 extra data at last but you can omit that the folloowing is the mysql query

    SELECT startdate, ( select startdate - INTERVAL 1 DAY from tester a where a.id = b.id +1) as enddate FROM tester b

提交回复
热议问题