当前位置: 代码迷 >> Sql Server >> 请教简单sql语句,多谢
  详细解决方案

请教简单sql语句,多谢

热度:27   发布时间:2016-04-27 21:34:28.0
请问简单sql语句,谢谢!
id                 tid                     createtime
1                     2                         2007-1-1
2                     2                         2007-1-2
3                     3                         2007-1-1
4                     3                         2007-1-2
...

按tid分组取createtime最小的id

谢谢

------解决方案--------------------
select a.id,a.tid,a.createtime from tb a inner join
(select tid,min(createtime) createtime from tb group by tid) b
on a.tid=b.tid and a.createtime = b.createtime
------解决方案--------------------
select t.* from tabname t where not exists(select 1 from tabname where tid=t.tid and createtime <t.createtime)
  相关解决方案