【发布时间】:2015-03-02 19:07:21
【问题描述】:
给定下表。
CREATE TABLE example (
a integer,
b integer,
c integer,
UNIQUE (a, b)
);
如何为每个a 获得一行,这样c 是a 的最大值?
例如给定下表,
a|b|c
-----
1 1 1
1 2 2
2 1 9
3 2 4
3 3 5
3 4 6
我应该回来
a|b|c
-----
1 2 2
2 1 9
3 4 6
【问题讨论】:
-
也许这个问题的标题应该是“Not so tricky SQL”
-
另见(可能重复?)stackoverflow.com/questions/3800551/… 和(MySQL 但一些可移植技术)stackoverflow.com/questions/8748986/…
标签: sql postgresql greatest-n-per-group