鉴于下表。Tricky Postgresql查询
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 t ricky SQL“ – Hogan 2015-03-02 19:13:27
另请参见(可能重复?)http://stackoverflow.com/questions/3800551/select-first-row-in-each-group-by-group?rq=1和(MySQL但一些便携式技术) http://stackoverflow.com/questions/8748986/get-records-with-highest-smallest-whatever-per-group – IMSoP 2015-03-05 12:46:36