我有一个点模式在Postgres,其中的皮卡和下降时间和地点的每次出租车旅行记录了几个月。我需要计算一个时间窗口(例如,从00:00到03:00)在给定时间间隔(例如3月5日至3月27日)的出租车出行次数。因此,在给定的例子中,我需要计算出发生在5、6和7、.和3月27日00:00至03:00之间的出租车出行总数。
我发现的唯一函数是'date_trunc',但我并不认为它适合,因为窗口大小已经固定了。
发布于 2018-03-27 21:35:45
drop table if exists taxi_trips;
create table taxi_trips
( pickup timestamp
, dropoff timestamp null
, notes varchar(100)
);
insert into taxi_trips (pickup, dropoff, notes) values ('2/28/2018 07:15', '2/28/2018 7:35', 'not found, date too early');
insert into taxi_trips (pickup, dropoff, notes) values ('3/5/2018 01:15', '3/5/2018 1:35', 'found');
insert into taxi_trips (pickup, dropoff, notes) values ('3/5/2018 06:15', '3/5/2018 6:35', 'not found, outside time window');
insert into taxi_trips (pickup, dropoff, notes) values ('3/6/2018 01:15', '3/6/2018 1:35', 'found');
insert into taxi_trips (pickup, dropoff, notes) values ('3/6/2018 06:15', '3/6/2018 6:35', 'not found, outside time window');
insert into taxi_trips (pickup, dropoff, notes) values ('4/1/2018 07:15', '4/1/2018 7:35', 'not found, date too late');
select count(*)
from taxi_trips
where pickup between '3/5/2018' and '3/28/2018'
and extract (hour from pickup) between 0 and 3
https://stackoverflow.com/questions/49522124
复制相似问题