如何合并连续的重复状态行 - Sql Server

时间:2011-10-24 05:02:58

标签: sql sql-server

有人可以帮我将连续的重复状态行合并为一个。请参阅下文。

示例:我的当前表:

enter image description here

输出应该是:

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用GROUP BY

SELECT ProductID, Status, MAX([Date]) AS RequestDate
FROM YourTable
GROUP BY ProductID, Status, YEAR([Date])
ORDER BY MAX([Date])

答案 1 :(得分:0)

select productid, status , max([date]) from table
group by productid, status