1

我有以下数据:

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 返回最后修改的记录。

4

2 回答 2

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
于 2013-05-08T06:31:27.290 回答
0

尝试以下:

select * from tableName where ModifiedOn=(select max(ModifiedOn) from tableName) group by SalesID
于 2013-05-08T06:37:10.033 回答