具体如图所示,希望通过sql查询生成报表,
解决方案
100
SELECT t.品名, t.库存 SUM(CASE t1.部门 WHEN "IS" THEN t1.使用量 ELSE "" END ) AS `IS`, SUM(CASE t1.部门 WHEN "ACC" THEN t1.使用量 ELSE "" END ) AS `ACC`, SUM(CASE t1.部门 WHEN "GM" THEN t1.使用量 ELSE "" END ) AS `GM`, SUM(CASE t1.部门 WHEN "DEP" THEN t1.使用量 ELSE "" END ) AS `DEP`, SUM(CASE t1.部门 WHEN "AIR" THEN t1.使用量 ELSE "" END ) AS `AIR` FROM 材料表 AS t LEFT JOIN 申请表 AS t1 ON t.品名 = t1.品名