SQL 成绩统计排序

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/CPythonJava/article/details/80328493

Test 表
id epid name suject score
1 1 张小三 技术 89
2 1 张小三 理论 70
3 1 张小三 效率 79
4 2 李小四 技术 89
5 2 李小四 效率 30
6 2 李小四 理论 50


关键字
DESC 降序
ASC 升序
SUM() 统计函数

计算每个员工的总分并排名(要求显示字段:姓名、总成绩) 降序

SELECT SUM(score), epid,name FROM test GROUP BY epid, name ORDER BY SUM(score) Desc

SELECT name AS 姓名,SUM(score) AS 总成绩 FROM test GROUP BY epid ORDER BY SUM(score) Desc

SELECT name,SUM(score) FROM test GROUP BY name ORDER BY SUM(score) Desc

计算每个员工的总分并排名(要求显示字段:工号、姓名、总成绩) 降序

SELECT epid AS 工号,name AS 姓名,SUM(score) AS 总成绩 FROM test GROUP BY epid ORDER BY SUM(score) Desc

计算每个员工的总分并排名(要求显示字段:工号、姓名、总成绩) 升序


这块有点疑问?ASC 为升序,为什么在中文姓名排序时变成了降序

SELECT epid AS 工号,name AS 姓名,SUM(score) AS 总成绩 FROM test GROUP BY epid ORDER BY SUM(score) ASC

计算每个员工的总分并排名(要求显示字段:工号、姓名、总成绩) 按中文姓名首字排序 降序

SELECT epid AS 工号,name AS 姓名,SUM(score) AS 总成绩 FROM test GROUP BY epid ORDER BY name ASC

计算每个员工的总分并排名(要求显示字段:工号、姓名、总成绩) 按中文姓名首字排序 升序

SELECT epid AS 工号,name AS 姓名,SUM(score) AS 总成绩 FROM test GROUP BY epid ORDER BY name DESC

展开阅读全文

没有更多推荐了,返回首页