您好,有人可以告诉我此示例数据透视命令中的错误是什么
SELECT *
FROM
(
SELECT *
FROM issued
) Src
PIVOT
( SUM(quantity)
FOR team IN (production,wastage,staff)
) AS Pvt;
我会做有条件聚合:
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