SQL向每个学生的总成绩,输出学号和总成绩,按总成绩排序(降序),若总成绩相同,再按学号排序(升序)。

SQL语句怎么写 ?
2025年03月01日 17:07
有2个网友回答
网友(1):

select xuehao as 学号,score as 总成绩 from CJB
where xuehao in(select xuehao from XSB)
group by xuehao,score
order by score desc,xuehao

网友(2):

select id as 学号, sum(score) as 总成绩
from 成绩表
group by id
order by sum(score) desc, id asc