我試圖選擇具有max(date_added)付費方面的行,以僅在col_a和col_b中使用重複值,log_id是唯一的。我已經看到DISTINCT ON和使用窗口函數的解決方案,但是我無法獲得正確的語法來獲得我想要的結果。根據最大日期時間戳選擇列
從這個表:
+--------+-------+-------+-------+-------+-------+-------------------------+ | log_id | col_a | col_b | col_c | col_d | col_e | date_added | +--------+-------+-------+-------+-------+-------+-------------------------+ | 1 | ACME | West | 14 | 27 | A | 2016-01-01 12:45:00.453 | | 2 | ACME | West | 17 | 31 | A | 2016-01-02 07:33:24.551 | | 3 | ACME | East | 13 | 27 | B | 2016-01-01 11:43:21.223 | | 4 | ACME | East | 17 | 28 | A | 2016-01-03 09:15:50.113 | +--------+-------+-------+-------+-------+-------+-------------------------+
我怎樣才能返回此:
+--------+-------+-------+-------+-------+-------+-------------------------+ | log_id | col_a | col_b | col_c | col_d | col_e | date_added | +--------+-------+-------+-------+-------+-------+-------------------------+ | 2 | ACME | West | 17 | 31 | A | 2016-01-02 07:33:24.551 | | 4 | ACME | East | 17 | 28 | A | 2016-01-03 09:15:50.113 | +--------+-------+-------+-------+-------+-------+-------------------------+