【MySQL】学生成绩
2024-08-22 20:04:36
- 统计每个人的总成绩排名
select stu.`name`,sum(stu.score) as totalscore
from stu
GROUP BY `name`
order by totalscore
- 统计每门课程的总分排序
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
这个方法会保留重复成绩
最新文章
- ORM系列之二:EF(2)Code First
- npm(cnpm)介绍
- .Net Core 之 Ubuntu 14.04 部署过程
- 天气api
- UML系列02之 UML类图(一)
- vim自定义配色方案,图文并茂
- UIDatePicker的简单用法
- 14的路 MySQL的btree索引和hash索引的区别
- T-SQL实例 函数结果设置为列别名
- hdu 2544
- Mongodb中Sharding集群
- LuaBridge 中C++类和继承示例
- React Native 系列(一) -- JS入门知识
- JavaScript要点汇总——The Most Important
- .Net core的日志系统
- 9foundation
- 实现一个简单的vue-router
- VS2010与VS2013中的多字节编码与Unicode编码问题
- 数据结构:IO读写频繁的青睐,B树和B+树
- JNI探秘-----FileInputStream的read方法详解
热门文章
- IIS设置URL重写,实现页面的跳转的重定向方法
- Linux基础五:网络配置与管理
- MySQL5.5.33对应的JDBC驱动包怎样使用?
- 析构函数与this指针
- 快上车丨直播课“Hello ArkansasUI:初识Slider组件(eTS语言)”来啦!
- Rainbond通过插件整合SkyWalking,实现APM即插即用
- No &#39;Access-Control-Allow-Origin&#39; header: 跨域问题踩坑记录
- Codeforces 702F - T-shirts(平衡树+势能分析)
- Codeforces 679E - Bear and Bad Powers of 42(线段树+势能分析)
- 【基因组注释】ncRNA注释