我有一个日期范围内开始和结束 unix 时间戳的临时表:
create temporary table rr (t timestamp);
insert into rr (t)
select generate_series(
(select timestamp 'epoch' + create_dte_timestamp * INTERVAL '1 second'
from data
order by create_dte_timestamp asc limit 1),
current_timestamp, interval '1 day');
create temporary table ts (s numeric(10), e numeric(10));
insert into ts (s, e)
select date_part('epoch', (to_timestamp(to_char(t, 'MM/DD/YYYY 00:00:00'),
'MM/DD/YYYY HH24:MI:SS')) at time zone 'UTC')::int,
date_part('epoch', (to_timestamp(to_char(t, 'MM/DD/YYYY 23:59:59'),
'MM/DD/YYYY HH24:MI:SS')) at time zone 'UTC')::int from rr order by t asc;
我想对 ts 表的每一行执行查询:
select count(id) from data
where create_dte_timestamp >= ts.s and create_dte_timestamp <= ts.e
我怎样才能做到这一点?