简体   繁体   English

选择 mysql 中具有相同值的行

[英]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_grade id_student id_student courses培训班 ke
1 1 2001 2001年 A一个 2 2
2 2 2001 2001年 A一个 1 1
3 3 2001 2001年 B 1 1
4 4 2002 2002年 A一个 2 2
5 5 2002 2002年 A一个 1 1

and expected result is:预期结果是:

id_grade id_grade id_student id_student courses培训班 ke
1 1 2001 2001年 A一个 2 2
3 3 2001 2001年 B 1 1
4 4 2002 2002年 A一个 2 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM