PostgreSQL 实现按月按年,按日统计 分组统计

endtime 是 timestamp

select to_char(endtime, 'YYYY-MM-DD') as d ,  count(objectid) 
FROM sde.polygon where endtime>='2004-09-01 00:00:00' and endtime <='2004-10-01 23:59:59' group by d

endtime 是 字符串时

select to_char(to_timestamp(endtime::bigint), 'YYYY-MM-DD') as d ,  count(objectid) 
FROM sde.polygon where endtime>='2004-09-01 00:00:00' and endtime <='2004-10-01 23:59:59' group by d
原文地址:https://www.cnblogs.com/james-roger/p/11392436.html