各位大侠帮忙了,这个sql怎么写

zxq68677511 2006-03-18 03:50:56
有表:
id name score
1 '张' 88
2 '张' 90
3 '王' 80
4 '王' 78
求:每个name中score最高的id,结果应该是:2--90;3--80
问:这个sql怎么写?急!
...全文
67 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vinsonshen 2006-03-18
  • 打赏
  • 举报
回复
select * from 表名 as a where not exists (select * from 表名 where name=a.name and score >a.score)
wangdehao 2006-03-18
  • 打赏
  • 举报
回复
select * from tb a
where not exists(
select * from tb
where name=a.name and score>a. score
)

----or:

select * from tb a inner join
(select name,score=max(score)
from tb group by name) b
on a.name = b.name and a.score=b.score


22,301

社区成员

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

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