求一条sql的写法

MySql 码拜 8年前 (2016-02-14) 863次浏览
一个记录成绩的表
id    user    score
1     张三       27
2     张三       30
3     李四       40
4     李四       34
5     王五       40
说明:每个人可以参加多次考试,最终计成绩时,只能取最高值,也就是结果为:
id    user    score
2     张三       30
3     李四       40
5     王五       40
sql怎么写
解决方案

4

select a.* from `一个记录成绩的表` a where not exists (select 1 from `一个记录成绩的表` b where a.user=b.user and a.score < b.score)
假如某个用户有两次的成绩是一样的 ,而且是最高值,会统计出这两次

4

select  user1,max(score)
from (
select 1 id,”张三” user1,27 score union all
select 2 id,”张三” user1,30 score union all
select 3 id,”李四” user1,40 score union all
select 4 id,”李四” user1,34 score union all
select 5 id,”王五” user1,40 score
)s
group by user1

1

max() 就行了。

3

select id,user ,max(score)
from tb
group by id,user

3

SELECT ID, USR, MAX(SCORE)
FROM SCORE
GROUP BY USR;

1

SELECT id,user,max(score) AS score FROM tb GROUP BY user;

2

SELECT ID, USR, MAX(SCORE)
FROM SCORE
GROUP BY USR;

2

SELECT max(id) as ID,user,max(score) as score FROM  TableName GROUP BY user;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求一条sql的写法
喜欢 (0)
[1034331897@qq.com]
分享 (0)