开发者

SQL query to order on two related datetime columns

I have a SQL Server table with two columns, startDate and endDate. I need a query that returns the rows such that the startDate of the next row matches the endDate of the current row. For example

startDate - endDate

2011/01/01 - 2011/01/02

2011/01/02 - 2011/01/05

2011/01/05 - 2011/01/13

2011/01/13 - 2011/01/15

... if there is no start matching previous end then just grab 开发者_如何转开发next startDate...

2011/01/19 - 2011/01/23

2011/01/23 - 2011/01/25


select t1.StartDate, t1.EndDate from Dates t1 inner join Dates t2 on t1.EndDate=t2.StartDate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜