mysql pivot

mysql 无pivot功能

 

select company,
sum(case when establish=’16-Jan’ then quantity else 0 end) as ’16-Jan’,
sum(case when establish=’16-Feb’ then quantity else 0 end) as ’16-Feb’,
sum(case when establish=’16-Mar’ then quantity else 0 end) as ’16-Mar’,
sum(case when establish=’16-Apr’ then quantity else 0 end) as ’16-Apr’
FROM train
group by company
order by company

发表评论

电子邮件地址不会被公开。 必填项已用*标注