Postgresql:选择其他字段的唯一对顺序

时间:2016-03-05 05:59:35

标签: sql postgresql distinct

我想选择最新的(order by id desc)唯一对date_start, date_finish

CREATE TABLE some (
    id SERIAL, 
    date_start TIMESTAMP,
    date_finish TIMESTAMP
);

1 个答案:

答案 0 :(得分:1)

怎么样:

select date_start, date_finish
from some
group by date_start, date_finish
order by max(id) desc