GYLOVECY 于 2016.03.23 16:05 提问

2个回答

enpterexpress   2016.03.23 16:12

group by month

danielinbiti      2016.03.23 16:15
``````select months 月份,type1+type2+type3 总数
,case when type1>0 then 1 else 0 then 执照1
,case when type2>0 then 1 else 0 then 执照2
,case when type3>0 then 1 else 0 then 执照3
from(
select yeas,months
,case when licenseType=1 then counts else 0 end type1
,case when licenseType=2 then counts else 0 end type2
,case when licenseType=3 then counts else 0 end type3
from 表
) a
``````
danielinbiti 回复GYLOVECY: 能解决问题满足自己要求就是好办法

GYLOVECY SELECT months as 月份, sum(counts) as 总数, (select SUM(t.counts) from doctorInnerTable t where t.months=mm.months and t.years=mm.years and t.licenseType='1') as 执照1, (select SUM(t.counts) from doctorInnerTable t where t.months=mm.months and t.years=mm.years and t.licenseType='2') as 执照2, (select SUM(t.counts) from doctorInnerTable t where t.months=mm.months and t.years=mm.years and t.licenseType='3') as 执照3 FROM doctorInnerTable mm WHERE years = '2016' GROUP BY months

GYLOVECY 可能是我太笨 刚刚接触sql 看不懂您这么深的语句 现在我问题已经解决 虽然办法有点low ：