17,382
社区成员




select to_char(回帖时间,'yyyy-mm') 月份,count(1) 每月回帖总数,
count(distinct 回帖用户) 回帖用户数
from tb
--加个where to_char(回帖时间,'yyyy-mm')='2010-05' 就是5月的,不加则是每个月的
group by to_char(回帖时间,'yyyy-mm')
with temp as(
select 1 id,'aaaaaa' userid,to_date('2010-5-15 10:20:20','yyyy-mm-dd hh24:mi:ss') retime from dual
union all
select 2 id,'bbbbbb' userid,to_date('2010-5-16 10:20:20','yyyy-mm-dd hh24:mi:ss') retime from dual
union all
select 3 id,'cccccc' userid,to_date('2010-5-17 10:20:20','yyyy-mm-dd hh24:mi:ss') retime from dual
union all
select 4 id,'dddddd' userid,to_date('2010-5-18 10:20:20','yyyy-mm-dd hh24:mi:ss') retime from dual
union all
select 5 id,'aaaaaa' userid,to_date('2010-5-18 19:29:55','yyyy-mm-dd hh24:mi:ss') retime from dual
union all
select 6 id,'aaaaaa' userid,to_date('2010-5-18 20:33:42','yyyy-mm-dd hh24:mi:ss') retime from dual
)
select count(id) 回帖总数,count(distinct userid) 回帖用户数 from temp where to_char(retime,'yyyy-mm')='2010-05'