I have the following sample data in my table:
ID GRADE
1 54
1 53
1 52
2 78
2 75
2 74
3 43
3 42
3 41
This is gotten from the query: "SELECT ID,GRADE FROM TABLE ORDER BY GRADE DESC;" The ID is not a primary key.
I want to obtain the data like this:
ID GRADE
1 54
2 78
3 43
That is, I want to get the value of all records that are the first distinct ones in terms of the ID.
Any suggestions?
I think you need this simple group by
:
select ID, max(GRADE)
from TABLE
group by ID
order by ID
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.