首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教简单sql语句,多谢

2012-01-31 
请问简单sql语句,谢谢!idtidcreatetime122007-1-1222007-1-2332007-1-1432007-1-2...按tid分组取createtim

请问简单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)

热点排行