有表:
id name score
1 '张' 88
2 '张' 90
3 '王' 80
4 '王' 78
求:每个name中score最高的id,结果应该是:张--90;王--80
问:这个sql怎么写?急!
id name score
1 '张' 88
2 '张' 90
3 '王' 80
4 '王' 78
求:每个name中score最高的id,结果应该是:张--90;王--80
问:这个sql怎么写?急!
解决方案 »
- 可以再SqlServer2000的基础上再装一个2005吗
- 2个sql语句整合
- 广征经典的SQL语句回家过年
- 有什么SQL语句可以把一个表里的两个字段连接起来吗?是"竖"连接.不是:field1+field2连接!!!!!
- 怎么用SQL 语句找到网上的所有SQL SERVER的名字啊.
- 连接odbc数据源SQL Server 错误:14
- 请问SQL查询分析器怎么获取到当前系统物理内存大小和当前实际使用内存大小?
- 一个很奇怪的查询问题
- 天,我在win2000 server上竟装不上sqlserver 2000????
- sql 查询问题 快快
- 请各位大侠帮我改一个SQL语句,万分感谢!!!!!!!!!!!!!!!!!!!
- 高手帮忙:到底哪个语句才是SQL SERVER中修改列属性的?
from tb a
where not exists(select top 1 * from tb where name=a.name and score>a.score)
where not exists(
select * from tb where name=a.name and score>a. score
)
(
select name,score=max(score) from tb group by name
) b on a.name = b.name and a.score=b.score
有表:
id name score
1 '张' 88
2 '张' 90
3 '王' 80
4 '王' 78
求:每个name中score最高的id,结果应该是:2--90;3--80
问:这个sql怎么写?急!
union all select '张',90
union all select '王',80
union all select '王',78 select a.* from t a inner join
(
select name,score=max(score) from t group by name
) b on a.name = b.name and a.score=b.score
create table BB
(
id int,
name varchar(10),
scour int
)
insert BB select 1 , '张' ,88
insert BB select 2 , '张' ,90
insert BB select 3 , '王' ,80
insert BB select 4 , '王' ,78
select id , 分数 from BB,
(select name ,max(scour)分数 from BB group by name )CC
where BB.scour=CC.分数