M
score
INNER JOIN (
SELECT
t1.course_id,
t1.first_num,
t2.second_num
FROM
(
SELECT
course_id,
max(num) first_num
FROM
score
GROUP BY
course_id
) AS t1
INNER JOIN (
SELECT
score.course_id,
max(num) second_num
FROM
score
INNER JOIN (
SELECT
course_id,
max(num) first_num
FROM
score
GROUP BY
course_id
) AS t ON score.course_id = t.course_id
WHERE
score.num < t.first_num
GROUP BY
course_id
) AS t2 ON t1.course_id = t2.course_id
) AS t3 ON score.course_id = t3.course_id
WHERE
score.num >= t3.second_num
AND score.num <= t3.first_num
ORDER BY
course_id;
#可以用以下命令验证上述查询的正确性
SELECT
*
FROM
score
ORDER BY
course_id,
num DESC;
-- 21、查询不同课程但成绩相同的学号,课程号,成绩
-- 22、查询没学过“叶平”老师课程的学生姓名以及选修的课程名称;
-- 23、查询所有选修了学号为1的同学选修过的一门或者多门课程的同学学号和姓名;
-- 24、任课最多的老师中学生单科成绩最高的学生姓名
更多练习以及参考答案:https://www.cnblogs.com/clschao/articles/9995768.html
|