根据llyt分组查询对应的cjjgmc的对应列
select b.llyt,
sum(case when b.cjjgmc = '一车间' then b.hjje else 0 end) as yicj,
sum(case when b.cjjgmc = '二车间' and b.wlmc != '轮胎' then b.hjje else 0 end) as ercj,
sum(case when b.cjjgmc = '三车间' then b.hjje else 0 end) as sancj,
sum(case when b.cjjgmc = '四车间' and b.wlmc != '轮胎' then b.hjje else 0 end) as sicj,
sum(case when b.cjjgmc = '总成车间' then b.hjje else 0 end) as zccj,
sum(case when b.cjjgmc = '车身车间' then b.hjje else 0 end) as cscj
from tables b group by llyt;
学习文章1:https://blog.csdn.net/shufusheng/article/details/50737255
学习文章2 https://blog.csdn.net/wo198711203217/article/details/52162894