mysql语句求排名前五的同学的姓名_求出每门课程成绩排名前五名的同学的姓名,分数和课程名?...
⾸先解决此种需求的查询要根据⾃⼰的业务或者需求,如果要是业务处理的话就简单多了。还有⼀个是mysql,⼀个是ORACL两种数据库,sqlserver我到没有研究,应该也有。笨⽅法多多包涵
简单的mysql语句MYSQL的是这个样⼦的应该有更简单的⽅法我就不多想了。
⼀:查询五个⼈的不同课程
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c
LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='语⽂' ORDER BY s.score DESC LIMIT 0,5) AS t
UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c
LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='数学' ORDER BY s.score DESC LIMIT 0,5) AS t
UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c
LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='英语' ORDER BY s.score DESC LIMIT 0,5) AS t
UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c
LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='其它' ORDER BY s.score DESC LIMIT 0,5) AS t
⼆:查询第三名的:
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c
LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='语⽂' ORDER BY s.score DESC LIMIT 2,1) AS t UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='数学' ORDER BY s.score DESC LIMIT 2,1) AS t UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c LEFT JOIN score AS s urse_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='英语' ORDER BY s.score DESC LIMIT 2,1) AS t UNION ALL
SELECT * from (
urse_name,s.score,sa.student_name FROM course AS c LEFT JOIN score AS s ON c.
course_urse_id
LEFT JOIN student AS sa ON s.student_id=sa.student_id
urse_name='其它' ORDER BY s.score DESC LIMIT 2,1) AS t 两种Sql只是分页控制不同就⾏。⼤神们肯定有更好的⽅法

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。