六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 194|回复: 0

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

[复制链接]

升级  1.67%

57

主题

57

主题

57

主题

举人

Rank: 3Rank: 3

积分
205
 楼主| 发表于 2013-1-30 01:32:29 | 显示全部楼层 |阅读模式
--按年分组查看   select     to_char(to_timestamp(start_time_of_date::bigint), 'YYYY') as d ,  count(cdr_id)  as  total_call,sum (call_duration::integer /60 +1)   as  total_duration  from  cdr   where  to_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)  as  total_call,sum (call_duration::integer /60 +1)   as  total_duration  from  cdr   where  to_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)  as  total_call,sum (call_duration::integer /60 +1)   as  total_duration  from  cdr   where  to_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  HH24 ' ) as d ,  count(cdr_id)  as  total_call,sum (call_duration::integer /60 +1)   as  total_duration  from  cdr   where  to_timestamp(start_time_of_date::bigint)  between  '2010-01-01'   and    '2010-12-12'   group by d  order  by  d--按秒分组查看     select     to_char(to_timestamp(start_time_of_date::bigint), 'YYYY-MM-DD  HH24:MI:SS ' ) as d ,  count(cdr_id)  as  total_call,sum (call_duration::integer /60 +1)   as  total_duration  from  cdr   where  to_timestamp(start_time_of_date::bigint)  between  '2010-01-01'   and    '2010-12-12'   group by d[size=small]
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表