当前位置: 代码迷 >> Sql Server >> 请问sql查询有关问题,为每个objectGuid选出最新更新的两条记录
  详细解决方案

请问sql查询有关问题,为每个objectGuid选出最新更新的两条记录

热度:44   发布时间:2016-04-27 15:26:24.0
请教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)