pgsql数据库 按半小时分组 和 按一小时分组

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44266650/article/details/100525993

按半小时分组

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 

按一小时分组

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

猜你喜欢

转载自blog.csdn.net/weixin_44266650/article/details/100525993