我正在嘗試添加一個新列來計算當週每個包裝類型的總計百分比。組總數的百分比
以下代碼的結果如下。
所以我想新的列中顯示升總數的百分比爲特定的星期。
代碼:
SET DATEFIRST 1
SELECT
DATEPART (wk, t0.U_ORC_BE_ProdDate) AS [Week Produced],
--Display week number of date produced
(
CASE
WHEN t5.U_ORC_BE_NAME LIKE '%Cans%'
THEN 'Cans'
WHEN t5.U_ORC_BE_NAME LIKE '%Bottles%'
THEN 'Bottles'
WHEN t5.U_ORC_BE_NAME LIKE '%Key Keg%'
THEN 'Key Keg'
WHEN t5.U_ORC_BE_NAME LIKE '%SS Keg%'
THEN 'SS Keg'
WHEN t5.U_ORC_BE_NAME LIKE '%E-Keg%'
Then 'SS Keg'
END
)AS [Pack Type],
--Collate item types to pack types
sum(t5.U_ORC_BE_HECTOLITER * t0.CmpltQty) AS [Total Hectoliters]
--Calculate total HL in the order
FROM OWOR T0
INNER JOIN OITT T1 ON T0.ItemCode = T1.Code
INNER JOIN OITM T2 ON T1.Code = T2.ItemCode
LEFT JOIN [@ORC_BE_PACK_TYPE] t5 ON t5.Code = t2.U_ORC_BE_PACK_TYPE
LEFT JOIN [@ORC_BE_STYLE_H] t6 ON t6.Code= t2.U_ORC_BE_ShortCode
WHERE
(t5.U_ORC_BE_HECTOLITER * t0.CmpltQty) != 0
AND U_ORC_BE_ProcessType = 'Packaging'
AND
(
T0.[U_ORC_BE_ProdDate] >= dateadd(wk, datediff(wk, 0, getdate()) - 13, 0)
AND T0.[U_ORC_BE_ProdDate] < dateadd(wk, datediff(wk, 0, getdate()), 0)
)
--For previous 12 weeks
GROUP BY datepart(wk, t0.U_ORC_BE_ProdDate),
t0.U_Operator,
(
CASE
WHEN t5.U_ORC_BE_NAME LIKE '%Cans%'
THEN 'Cans'
WHEN t5.U_ORC_BE_NAME LIKE '%Bottles%'
THEN 'Bottles'
WHEN t5.U_ORC_BE_NAME LIKE '%Key Keg%'
THEN 'Key Keg'
WHEN t5.U_ORC_BE_NAME LIKE '%SS Keg%'
THEN 'SS Keg'
WHEN t5.U_ORC_BE_NAME LIKE '%E-Keg%'
Then 'SS Keg'
END
)
ORDER BY datepart (wk, t0.U_ORC_BE_ProdDate) ASC
太棒了。非常感謝。 – coblenski