鑑於下表。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