ClaimID ClaimStatusCode StatusDate
11, Closed, 2010-05-10 12:19:00.000
11, Open, 2010-05-25 09:30:00.000
11, Closed, 2011-06-01 00:00:00.000
11, Open, 2011-06-10 00:00:00.000
22, Closed, 2011-03-14 00:00:00.000
22, Open, 2011-05-04 00:00:00.000
33, Closed, 2007-12-19 17:19:00.000
33, Open, 2007-12-24 12:07:00.000
**33, Open, 2008-09-08 15:36:00.000**
44, Closed, 2008-11-19 17:19:00.000
44, Open, 2008-12-24 12:07:00.000
44, Closed, 2009-07-28 15:36:00.000
對於任何ClaimID,如果打開聲明狀態由open打開,則不需要第二個打開狀態行。每次關閉都會被打開。 此處最後一行ClaimID 33與StatusDate 2008-09-08 15:36:00.000不是必需的(以星號標出以供參考)。 我嘗試使用rownumber函數,但沒有運氣。刪除連續的行
的答案應該是:每次夜
ClaimID ClaimStatusCode StatusDate
11, Closed, 2010-05-10 12:19:00.000
11, Open, 2010-05-25 09:30:00.000
11, Closed, 2011-06-01 00:00:00.000
11, Open, 2011-06-10 00:00:00.000
22, Closed, 2011-03-14 00:00:00.000
22, Open, 2011-05-04 00:00:00.000
33, Closed, 2007-12-19 17:19:00.000
33, Open, 2007-12-24 12:07:00.000
44, Closed, 2008-11-19 17:19:00.000
44, Open, 2008-12-24 12:07:00.000
44, Closed, 2009-07-28 15:36:00.000
如果只有它是那麼容易。這不處理ClaimID = 11,它已被打開,關閉,然後再次打開。 –
但它也刪除了ClaimID 11的兩條記錄。 – Punia
我看到了 - 然後使用HAVING子句找到具有太多「打開」狀態的子句。順便說一句 - 根據你給的例子,這看起來不太好,但我假設(你沒有在你的例子中)每個索賠的第一個記錄將是'開放'而不是'關閉'。 – Chains