一、原表
二、语句
select type,
sum(if(date='2019-10-1',num,null)) as '20191001',
sum(if(date='2019-10-2',num,null)) as '20191002',
sum(if(date='2019-10-3',num,null)) as '20191003'
from del
group by type;
select type,
sum(case when date='2019-10-1' then num else null end) as '20191001',
sum(case when date='2019-10-2' then num else null end) as '20191002',
sum(case when date='2019-10-3' then num else null end) as '20191003'
from del
group by type;
三、结果