1. 统计每个人的总成绩排名
select stu.`name`,sum(stu.score) as totalscore
from stu
GROUP BY `name`
order by totalscore
  1. 统计每门课程的总分排序

SELECT
stu.class,
sum(stu.score) as totalscore
FROM
stu
GROUP BY
stu.class
ORDER BY
totalscore desc

结果

3.求每门课的前三名

SELECT
*
FROM
stu a
WHERE
( SELECT count(*) FROM stu b WHERE b.class = a.class AND a.score < b.score ) < 3
ORDER BY
a.class,
a.score DESC

SELECT
*
FROM
stu a
WHERE
( SELECT count(1) FROM stu b WHERE b.class = a.class AND a.score < b.score ) < 3
ORDER BY
a.class,
a.score DESC

这个方法会保留重复成绩

最新文章

  1. ORM系列之二:EF(2)Code First
  2. npm(cnpm)介绍
  3. .Net Core 之 Ubuntu 14.04 部署过程
  4. 天气api
  5. UML系列02之 UML类图(一)
  6. vim自定义配色方案,图文并茂
  7. UIDatePicker的简单用法
  8. 14的路 MySQL的btree索引和hash索引的区别
  9. T-SQL实例 函数结果设置为列别名
  10. hdu 2544
  11. Mongodb中Sharding集群
  12. LuaBridge 中C++类和继承示例
  13. React Native 系列(一) -- JS入门知识
  14. JavaScript要点汇总——The Most Important
  15. .Net core的日志系统
  16. 9foundation
  17. 实现一个简单的vue-router
  18. VS2010与VS2013中的多字节编码与Unicode编码问题
  19. 数据结构:IO读写频繁的青睐,B树和B+树
  20. JNI探秘-----FileInputStream的read方法详解

热门文章

  1. IIS设置URL重写,实现页面的跳转的重定向方法
  2. Linux基础五:网络配置与管理
  3. MySQL5.5.33对应的JDBC驱动包怎样使用?
  4. 析构函数与this指针
  5. 快上车丨直播课“Hello ArkansasUI:初识Slider组件(eTS语言)”来啦!
  6. Rainbond通过插件整合SkyWalking,实现APM即插即用
  7. No &#39;Access-Control-Allow-Origin&#39; header: 跨域问题踩坑记录
  8. Codeforces 702F - T-shirts(平衡树+势能分析)
  9. Codeforces 679E - Bear and Bad Powers of 42(线段树+势能分析)
  10. 【基因组注释】ncRNA注释