0
行を列に転置しようとしています。 サプライヤーごとに1行が表示されます。Netezzaの行から重複を示す列
これは、与えられたテーブルです:
SELECT
SupplierName,
CASE WHEN YearID = 2018 THEN Shipping_cost ELSE NULL END SC_2018,
CASE WHEN YearID = 2017 THEN Shipping_cost ELSE NULL END SC_2017,
CASE WHEN YearID = 2016 THEN Shipping_cost ELSE NULL END SC_2016,
CASE WHEN YearID = 2018 THEN Retail_Percent_2018 ELSE NULL END Retail_2018,
CASE WHEN YearID = 2017 THEN Retail_Percent_2017 ELSE NULL END Retail_2017,
CASE WHEN YearID = 2016 THEN Retail_Percent_2016 ELSE NULL END Retail_2016
FROM
(
SELECT
SUPL.SUP_NAM AS SupplierName,
SUPL.SUPL_CST AS Shipping_cost,
(SELECT SUM(Shipping_Cost) FROM MM_TRX_TABLE S
WHERE YearID = '2018') AS GRANDTOTAL_2018,
(SELECT SUM(Shipping_Cost) FROM MM_TRX_TABLE S
WHERE YearID = '2017') AS GRANDTOTAL_2017,
(SELECT SUM(Shipping_Cost) FROM MM_TRX_TABLE S
WHERE YearID = '2016') AS GRANDTOTAL_2016,
SUM(SUPL.Retail_Cost) AS Retail_Total,
CASE WHEN YearID = 2018
THEN (Retail_Total/GRANDTOTAL_2018) * 100
ELSE NULL END AS Retail_Percent_2018,
CASE WHEN YearID = 2017
THEN (Retail_Total/GRANDTOTAL_2017) * 100
ELSE NULL END AS Retail_Percent_2017,
CASE WHEN YearID = 2016
THEN (Retail_Total/GRANDTOTAL_2016) * 100
ELSE NULL END AS Retail_Percent_2016,
FROM MM_TRX_TABLE S
WHERE YEARID IN ('2018', '2017', '2016')
GROUP BY
SupplierName,
YEARID,
)DTL
ORDER BY GrossMargin DESC
私が見えるようにテーブルを期待している:
しかし、私は複数の行で繰り返さサプライヤーを取得します。 enter image description here
このクエリを使用して得られる出力を追加できますか? –
私の結果Andrewが更新されました。前もって感謝します。 – Jasmine