简体   繁体   中英

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. and i would like to choose higher "KE" column if they have id_student and courses column..

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? Thanks in advance!

Try this:

select id_grade, id_student, courses, max(ke) ke
from temp
group by id_student, courses

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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