select 年,
sum(if(分类='m1',值,0.0)) as 'm1',
sum(if(分类='m2',值,0.0)) as 'm2',
sum(if(分类='m3',值,0.0)) as 'm3',
sum(if(分类='m4',值,0.0)) as 'm4'
from (select *,case when 月=1 then 'm1'
              when 月=2 then 'm2'
              when 月=3 then 'm3'
              when 月=4 then 'm4'
        end as 分类
from cook) as new1
group by 年
order by 年 asc;