17,086
社区成员
发帖
与我相关
我的任务
分享
create table table_tmp as
select 'a' username, '20170101' time_ from dual union all
select 'b' username, '20170101' time_ from dual union all
select 'c' username, '20170102' time_ from dual union all
select 'a' username, '20170101' time_ from dual union all
select 'b' username, '20170102' time_ from dual union all
select 'a' username, '20170130' time_ from dual union all
select 'b' username, '20170201' time_ from dual union all
select 'c' username, '20170228' time_ from dual ;
select * from (select '统计' " ",count(*) counts,substr(time_,5,2) mon from table_tmp group by substr(time_,5,2))
pivot(sum(counts) for mon in ('01' "1月",'02' "2月",'03' "3月",'04' "4月",'05' "5月",'06' "6月"))