pgsql database and grouped by half an hour by hour basis packet

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44266650/article/details/100525993

Packet by a half hour

select 

case when substr( to_char(capturetime, 'yyyy-mm-dd hh24:mi'),15, 16) :: integer <=30 
then to_char( capturetime, 'yyyy-mm-dd hh24')||':30' 
else to_char( capturetime, 'yyyy-mm-dd hh24')||':00'
end as row_date2, count(1)

from t_ori_mac_data_xinwangcheng
where capturetime >= '2019-09-03'
group by row_date2 

Grouped by hour

select to_char(capturetime,'hh24'),count(mac)
from  t_ori_mac_data_xinwangcheng 
where capturetime >= '2019-09-03'
group by to_char(capturetime,'hh24')

Guess you like

Origin blog.csdn.net/weixin_44266650/article/details/100525993