【发布时间】:2019-01-16 09:23:56
【问题描述】:
我有表格数据,需要获取一个结果集,其中包含 id 的 max(timestamp) 行。参数之间的时间戳 数据样本如下所示:example data
我不知道如何为每个 id 和参数之间的 max(timestamp) 获取一行。
select id,
tgl,
max(case when tgl::timestamp between '2018-08-01 06:00'::timestamp and '2018-08-02 06:00'::timestamp
then tgl::timestamp else null end) clock
from tb_raw_pola_internal
where id = '0023817'
group by 1, 2
order by 1,2 asc
limit 1
结果是:
我的结果集应该是2018-08-02 02:05:00
谁能成为我的英雄? :) 谢谢之前
【问题讨论】: