PostgreSQL 实现按月按年,按日统计 分组统计
--按年分组查看select to_char(to_timestamp(start_time_of_date::bigint), 'YYYY') as d ,count(cdr_id)astotal_call,sum (call_duration::integer /60 +1) astotal_durationfromcdr
whereto_timestamp(start_time_of_date::bigint)between'2010-01-01' and '2010-12-12' group by d
--按月分组查看
select to_char(to_timestamp(start_time_of_date::bigint), 'YYYY-MM') as d ,count(cdr_id)astotal_call,sum (call_duration::integer /60 +1) astotal_durationfromcdr
whereto_timestamp(start_time_of_date::bigint)between'2010-01-01' and '2010-12-12' group by d
--按天分组查看
select to_char(to_timestamp(start_time_of_date::bigint), 'YYYY-MM-DD') as d ,count(cdr_id)astotal_call,sum (call_duration::integer /60 +1) astotal_durationfromcdr
whereto_timestamp(start_time_of_date::bigint)between'2010-01-01' and '2010-12-12' group by d
--按小时分组查看
select to_char(to_timestamp(start_time_of_date::bigint), 'YYYY-MM-DDHH24 ' ) as d ,count(cdr_id)astotal_call,sum (call_duration::integer /60 +1) astotal_durationfromcdr
whereto_timestamp(start_time_of_date::bigint)between'2010-01-01' and '2010-12-12' group by dorderbyd
--按秒分组查看
select to_char(to_timestamp(start_time_of_date::bigint), 'YYYY-MM-DDHH24:MI:SS ' ) as d ,count(cdr_id)astotal_call,sum (call_duration::integer /60 +1) astotal_durationfromcdr
whereto_timestamp(start_time_of_date::bigint)between'2010-01-01' and '2010-12-12' group by d
页:
[1]