一条查询获取每个科目最高分的学生信息

SELECT 
    a.* 
FROM
    ( SELECT class, max( score ) AS max FROM test1.NOT GROUP BY test1.NOT.class ) AS b,
    test1.NOT AS a 
WHERE
    b.class = a.class 
    AND b.max = a.score 
ORDER BY
    a.score DESC

SELECT
    a.* 
FROM
    test1.not AS a 
WHERE
    a.score = ( SELECT max( b.score ) FROM test1.not AS b GROUP BY b.class HAVING a.class = b.class ) 
ORDER BY
    a.score DESC
评论数量: 0

1
点赞
112
浏览
0
评论

贡献 7