我有以下数据:
SalesID Source Name Modified On
S12345 ABC John 5/8/2013 5:44
S12345 ABC Tom 5/8/2013 5:45
S11111 EFG Sam 5/8/2013 5:46
S11111 EFG Don 5/8/2013 5:47
我想编写一个SP或查询,它将返回第2行和第4行,即我想编写一个查询,该查询将根据不同的销售ID返回已删除的修改记录。
答案 0 :(得分:0)
我使用了以下查询,它对我来说效果很好
SELECT * FROM (Select Asu_OrderId ,ModifiedOn ,ROW_NUMBER() OVER(PARTITION BY Asu_OrderId order by ModifiedOn desc)AS R from Asu_callreason
where <condition>) AS A WHERE r=1
答案 1 :(得分:0)
试试以下内容:
select * from tableName where ModifiedOn=(select max(ModifiedOn) from tableName) group by SalesID