请问该sql语句怎么写

zealothasu 2003-04-23 02:08:47
a b c d
------------------------
AA 1 LL DD
AA 3 DD KK
BB 3 DD KJK
BB 2 SS DM
CC 9 AA MM

查询结果应该是
AA 1 LL DD
BB 2 SS KJK
CC 9 AA MM
也就是要把a列有相同值但字段b中最小的那一行查询出来

我用select a, min(b) from table1 group by a
可以把a, b两列查出来
但要是加上c,d列就不行了


那么怎么写??
...全文
23 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mjhnet 2003-04-23
  • 打赏
  • 举报
回复
感觉乘长风的方法比较好
zealothasu 2003-04-23
  • 打赏
  • 举报
回复
谢谢大家的热情
SophiaWang 2003-04-23
  • 打赏
  • 举报
回复
select * from table1 b
where b = ( select min(b) from table1 where b.a = a group by a )
caiyunxia 2003-04-23
  • 打赏
  • 举报
回复
我用select distinct a.* from table1 a ,(select a,min(b) from table1 group by a) b
where a.a=b.a and a.b=b.b
SophiaWang 2003-04-23
  • 打赏
  • 举报
回复
select * from table1
where b = ( select min(b) from table1 group by a )
teaism 2003-04-23
  • 打赏
  • 举报
回复
select a.* from table1 a,(select a, min(b) as b from table1 group by a
) b where a.a=b.a and a.b=b.b
Rewiah 2003-04-23
  • 打赏
  • 举报
回复
需要的话加
order by a
Rewiah 2003-04-23
  • 打赏
  • 举报
回复
select * from tablename x
where b=(
select min(b) from tablename
where a=x.a
)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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