挣扎与枢轴Synta

问题描述 投票:0回答:1

您好,有人可以告诉我此示例数据透视命令中的错误是什么

SELECT *
FROM
(
 SELECT *
  FROM issued

 ) Src
 PIVOT
( SUM(quantity)  
FOR team IN (production,wastage,staff)
) AS Pvt;
mysql sql syntax pivot
1个回答
0
投票

我会做有条件聚合:

select col,
       sum(case when team = 'Production' then qty else 0 end) as production_qty,
       sum(case when team = 'wastage' then qty else 0 end) as wastage_qty,
       sum(case when team = 'staff' then qty else 0 end) as staff_qty
from issued
group by col --- use actual column name if any
© www.soinside.com 2019 - 2024. All rights reserved.