[英]choose rows that have the same value in mysql
In a [KHS] table, some rows have the same value for the id_student and courses column.在 [KHS] 表中,某些行的 id_student 和课程列具有相同的值。 and i would like to choose higher "KE" column if they have id_student and courses column..
如果他们有 id_student 和 courses 列,我想选择更高的“KE”列..
id_grade ![]() |
id_student ![]() |
courses![]() |
ke![]() |
---|---|---|---|
1 ![]() |
2001 ![]() |
A![]() |
2 ![]() |
2 ![]() |
2001 ![]() |
A![]() |
1 ![]() |
3 ![]() |
2001 ![]() |
B![]() |
1 ![]() |
4 ![]() |
2002 ![]() |
A![]() |
2 ![]() |
5 ![]() |
2002 ![]() |
A![]() |
1 ![]() |
and expected result is:预期结果是:
id_grade ![]() |
id_student ![]() |
courses![]() |
ke![]() |
---|---|---|---|
1 ![]() |
2001 ![]() |
A![]() |
2 ![]() |
3 ![]() |
2001 ![]() |
B![]() |
1 ![]() |
4 ![]() |
2002 ![]() |
A![]() |
2 ![]() |
What SQL statement should I use?我应该使用什么 SQL 语句? Thanks in advance!
提前致谢!
Try this:尝试这个:
select id_grade, id_student, courses, max(ke) ke
from temp
group by id_student, courses
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.