我有一組日期範圍同時包含部分和完全重疊的日期,就像這樣:消除和減少重疊的日期範圍
UserID StartDate EndDate
====== ========== ==========
1 2011-01-01 2011-01-02 <- A
1 2011-01-01 2011-01-10 <- A
1 2011-01-08 2011-02-15 <- A
1 2011-02-20 2011-03-10 <- B
2 2011-01-01 2011-01-20 <- C
2 2011-01-15 2011-01-25 <- C
使用T-SQL,我想創建一個新的數據集每個用戶,以消除重複數據,擴展範圍和消除在必要的冗餘數據,從而導致這樣的事情:如果需要
UserID StartDate EndDate
====== ========== ==========
1 2011-01-01 2011-02-15 ('A', three rows combined, extending the range)
1 2011-02-20 2011-03-10 ('B', no change, no overlaps here)
2 2011-01-01 2011-01-25 ('C', two rows combined)
光標是好的,但如果我可以毫不他們做到這一點就更好了。
什麼SQL Server中,2005 +的版本? – RichardTheKiwi 2011-03-06 21:35:39
是的,SQL Server 2005+。 – 2011-03-06 21:52:31