我有一张如下表:
att1 | att2 | num
------+--------+------+
wm1 | A | 1
wm6 | A | 3
wm5 | B | 4
wm7 | C | 2
wm0 | D | 1
wm2 | D | 2
wm3 | D | 2
wm4 | E | 1
我想要一个结果,它给我每个 att2 的最大数量。什么查询会给我下表?
att1 | att2 | num
------+--------+------+
wm6 | A | 3
wm5 | B | 4
wm7 | C | 2
wm2 | D | 2
wm3 | D | 2
wm4 | E | 1
编辑:我试过:
SELECT att2, max(num) FROM *original table* GROUP BY att2
但这会返回:
att2 | num
------+--------+
| A | 3
| B | 4
| C | 2
| D | 2
| D | 2
| E | 1