首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Postgres -查询时间序列模式

Postgres -查询时间序列模式
EN

Stack Overflow用户
提问于 2018-03-27 20:44:53
回答 1查看 54关注 0票数 0

我有一个点模式在Postgres,其中的皮卡和下降时间和地点的每次出租车旅行记录了几个月。我需要计算一个时间窗口(例如,从00:00到03:00)在给定时间间隔(例如3月5日至3月27日)的出租车出行次数。因此,在给定的例子中,我需要计算出发生在5、6和7、.和3月27日00:00至03:00之间的出租车出行总数。

我发现的唯一函数是'date_trunc',但我并不认为它适合,因为窗口大小已经固定了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-27 21:35:45

代码语言:javascript
运行
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49522124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档