我有这个数据集:
| ID | TYPE | PERCENT |
------|------|---------|
| 123 | A | 0.5 |
| 123 | B | 0.5 |
| 456 | A | 0.7 |
| 456 | B | 0.3 |
| 789 | A | 1 |
我想要以下结果:
| ID | TYPE | PERCENT |
------|------|---------|
| 123 | A | 0.5 |
| 456 | A | 0.7 |
| 789 | A | 1 |
也就是说,获取MAX(percent)
for eachid
和对应的type
.
我目前正在使用
SELECT ...
FROM
(SELECT [id], MAX([percent]) AS [p]
FROM [highest]
GROUP BY [id]) a
LEFT JOIN [highest] b
ON b.[id] = a.[id]
AND b.[percent] = a.[p]
并得到
| ID | P | TYPE | PERCENT |
--- --|-----|------|---------|
| 123 | 0.5 | A | 0.5 |
| 123 | 0.5 | B | 0.5 |
| 456 | 0.7 | A | 0.7 |
| 789 | 1 | A | 1 |