一个关于select语句的问题

javaxi 2008-09-22 03:24:26
一个表tbl1,数据如下:
col1 col2 col3 col4 col5 col6
A 1 2008-10-10 1 2 3
A 1 2008-10-01 5 4 1
A 1 2008-10-11 1 1 1
A 1 2008-10-15 2 2 2
B 2 2008-09-11 1 2 1
B 2 2008-09-10 2 2 1
B 2 2008-09-15 7 4 6
select 的时候,根据col1,col2分组,只显示日期最小那条数据,该如何实现?
希望得到的结果是:
A 1 2008-10-01 5 4 1
B 2 2008-09-10 2 2 1

select * from tbl1 group by col1, col2 having……
该如何编写呢?
...全文
43 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcxx2008 2008-09-22
  • 打赏
  • 举报
回复
关注中...

分组他们没说,自己补上
wxg22526451 2008-09-22
  • 打赏
  • 举报
回复
select * from @T a
where col3 in(select MIN(col3) from @T group by col1,col2)
113244 2008-09-22
  • 打赏
  • 举报
回复
关注。。
水族杰纶 2008-09-22
  • 打赏
  • 举报
回复
反了
[Quote=引用 1 楼 wufeng4552 的回复:]
select * from tbl1 t where not exists(select 1 from tbl1 where col1=t.col1 and col2=t.col2 and col3<t.col3)
[/Quote]
昵称被占用了 2008-09-22
  • 打赏
  • 举报
回复
select * from tbl1 a
where not exists (
select 1 from tbl1
where col1=a.col1
and col2=a.col2
and col3<a.col3
)

lgxyz 2008-09-22
  • 打赏
  • 举报
回复
select * from tbl1 a 
where not exists(select 1 from tal1 where col1=a.col1 and col2=a.col2 and col3<a.col3)
水族杰纶 2008-09-22
  • 打赏
  • 举报
回复
select * from tbl1 t where not exists(select 1 from tbl1 where col1=t.col1 and col2=t.col2 and col3>t.col3)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧