关于展示给定时间范围内的数据查询,本人做了两个查询,分别如下
1.查询指定时间范围内小时的数据,比如查询2020-03-20 10:00:00到2020-04-20 10:00:00时间范围内在所有09:00:00这个时间的数据,也就是查询每天10:00的数据
数据表中的事件字段为datatime,sql语句如下:
SELECT datatime, pm25 from 数据表 where datatime >= '2020-03-20 10:00:00' and datatime <'2020-04-20 10:00:00' and date_part('hour', datatime)=10 and stationcode = '130300053' order by datatime;
结果如图:共31条数据
2.查询事件范围内周几的数据,比如查询2020-03-20 10:00:00到2020-04-20 10:00:00时间范围内所有周一的数据
SQL语句如下:
SELECT pm25, EXTRACT(DOW FROM datatime) from 数据表 where datatime between '2020-03-20 00:00:00' and '2020-04-20 00:00:00' and EXTRACT(DOW FROM datatime) =1 and stationcode = '130300053';
结果如下图: