gpt4 book ai didi

mysql - 显示重复最大值

转载 作者:行者123 更新时间:2023-11-28 23:12:20 26 4
gpt4 key购买 nike

我有一张 table :

+----------------+----------------+------------------+-------+
| Student_Id | Student_Name | Assessment_Type | Mark |
+----------------+----------------+------------------+-------+
| 300 | John | Assignment | 1 |
| 200 | Liz | Final | 2 |
| 300 | John | Mid-term | 3 |
| 100 | Sue | Mid-term | 4 |
| 200 | Liz | Project | 5 |
| 300 | John | Assignment | 6 |
| 200 | Liz | Final | 7 |
| 300 | John | Mid-term | 8 |
| 100 | Sue | Mid-term | 8 |
| 200 | Liz | Project | 9 |
+----------------+----------------+------------------+-------+

我想找到按 Assessment_Type 分组的最高分数,如果有重复项,则显示两者,所以在这种情况下:

+----------------+----------------+------------------+-------+
| Student_Id | Student_Name | Assessment_Type | Mark |
+----------------+----------------+------------------+-------+
| 300 | John | Assignment | 6 |
| 200 | Liz | Final | 7 |
| 300 | John | Mid-term | 8 |
| 100 | Sue | Mid-term | 8 |
| 200 | Liz | Project | 9 |
+----------------+----------------+------------------+-------+

我只有其中一个:

SELECT Student_Id, Student_Name, Assessment_Type, max(mark) FROM STUDENT_ASSESSMENT group by Student_Id, Assessment_Type;

编辑:为问题添加了更多细节。

最佳答案

您可以在每个评估类型中找到最高分,然后将最高分和评估类型与每一行进行比较。

select * from STUDENTS_ASSESSMENT where (Assessment_Type,marks) in 
((select Assessment_Type,max(marks) from STUDENTS_ASSESSMENT groupby Assessment_Type));

关于mysql - 显示重复最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com