该sql语句用于统计2008年各月通过各种渠道收到简历的数量
SQL code:
select way_type_name,way_name,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec from(
select w.way_id , w.way_name,w.way_type_id,
sum(case when month(send_date)=1 then 1 else 0 end) as Jan,
sum(case when month(send_date)=2 then 1 else 0 end) as Feb,
sum(case when month(send_date)=3 then 1 else 0 end) as Mar,
sum(case when month(send_date)=4 then 1 else 0 end) as Apr,
sum(case when month(send_date)=5 then 1 else 0 end) as May,
sum(case when month(send_date)=6 then 1 else 0 end) as Jun,
sum(case when month(send_date)=7 then 1 else 0 end) as Jul,
sum(case when month(send_date)=8 then 1 else 0 end) as Aug,
sum(case when month(send_date)=9 then 1 else 0 end) as Sep,
sum(case when month(send_date)=10 then 1 else 0 end) as Oct,
sum(case when month(send_date)=11 then 1 else 0 end) as Nov,
sum(case when month(send_date)=12 then 1 else 0 end) as Dec
from tb_resume r inner join tb_way w
on r.way_id = w.way_id
where year(send_date) = 2008
group by w.way_id, w.way_name,w.way_type_id
)as g inner join tb_way_type wt
on g.way_type_id = wt.way_type_id
查询结果:
way_type_name way_name Jan Feb Mar Apr May Jun Jul Aug Sep Oc