Mysql 最高分和学生姓名
Mysql Maximum mark and student name
我需要获得每个科目的最高分,即 table 中的学生姓名。有六个科目。每个科目的排行榜名和分数
SELECT 不同的名称,MAX(evs) FROM eee2sem where(SELECT MAX(evs));
这只能用于获取一个主题结果。不是总分最高分和学生姓名,我需要 6 个结果。实际上我需要每个科目的最高分数和(分数持有者)学生姓名..
Name | Sub1 |sub2 | sub3 | sub4
----------------------------------
AAA | 90 | 92 | 85 | 90
BBB | 82 | 96 | 89 | 98
终于找到答案了,
SELECT name, sub1 FROM table name WHERE sub1 = (SELECT MAX (sub1) FROM table name) UNION SELECT name, sub2 FROM table name WHERE sub2 = (SELECT MAX (sub2) FROM table name) UNION SELECT name, sub3 FROM table name WHERE sub3 = (SELECT MAX (sub3) FROM table name) UNION SELECT name, sub4 FROM table name WHERE sub4 = (SELECT MAX (sub4);
我需要获得每个科目的最高分,即 table 中的学生姓名。有六个科目。每个科目的排行榜名和分数
SELECT 不同的名称,MAX(evs) FROM eee2sem where(SELECT MAX(evs));
这只能用于获取一个主题结果。不是总分最高分和学生姓名,我需要 6 个结果。实际上我需要每个科目的最高分数和(分数持有者)学生姓名..
Name | Sub1 |sub2 | sub3 | sub4
----------------------------------
AAA | 90 | 92 | 85 | 90
BBB | 82 | 96 | 89 | 98
终于找到答案了,
SELECT name, sub1 FROM table name WHERE sub1 = (SELECT MAX (sub1) FROM table name) UNION SELECT name, sub2 FROM table name WHERE sub2 = (SELECT MAX (sub2) FROM table name) UNION SELECT name, sub3 FROM table name WHERE sub3 = (SELECT MAX (sub3) FROM table name) UNION SELECT name, sub4 FROM table name WHERE sub4 = (SELECT MAX (sub4);