读书人

请问sql查询有关问题为每个objectGu

发布时间: 2012-02-09 18:22:27 作者: rapoo

请教sql查询问题,为每个objectGuid选出最新更新的两条记录
有一张表 table1 主要的字段如下:
guid 标识主键
objectGuid 所属对象 外键
updateTime 更新时间

现需要在这个表中为每一个objectGuid选出最新updateTime的两条记录

敬请赐教


[解决办法]

SQL code
select * from tb twhere updateTime in (select top 2 updateTime from tb where objectGuid =t.objectGuid  order by updateTime desc) 

读书人网 >SQL Server

热点推荐