【发布时间】:2015-06-12 11:11:48
【问题描述】:
我有下表players 和:
ID;color;race;score
1;"red";"elf";400
2;"blue";"elf";500
3;"green";"elf";300
4;"blue";"elf";200
5;"red";"elf";700
6;"red";"troll";100
7;"blue";"troll";400
8;"green";"troll";500
9;"red";"troll";400
10;"yellow";"troll";1000
11;"red";"nord";900
12;"green";"nord";100
13;"yellow";"nord";500
14;"blue";"nord";7000
我想要每场比赛的最高分数以及该球员的颜色和 ID。像这样
elf 700 red 5
nord 7000 blue 14
troll 1000 yellow 10
我可以得到的前两列:
select category,max(score)
from players
group by category;
但我无法添加该玩家的颜色和 ID。我该怎么做?
【问题讨论】:
-
我们不知道您的列名,但为什么以下内容不起作用:
select category,max(score), max(id), max(color) from players group by category;
标签: postgresql max groupwise-maximum