[英]SQL query to get all values of first distinct (given) column values
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;" 这是从查询中获得的:“ SELECT ID,GRADE FROM TABLE ORDER BY GRADE DESC;” The ID is not a primary key. 该ID不是主键。
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. 也就是说,我想获取所有在ID方面是第一个不同记录的记录的值。
Any suggestions? 有什么建议么?
I think you need this simple group by
: 我认为您需要这个简单的group by
:
select ID, max(GRADE)
from TABLE
group by ID
order by ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.