我有以下查詢:
(SELECT
art_nr
, MENG_STK as S01
FROM NW_ART@MMS_HK WHERE BESTAND_L = 1 AND HIER_FD in (8701)
AND art_nr in (43848))
Union
(Select art_nr, MENG_STK as S02
FROM NW_ART@MMS_HK WHERE BESTAND_L = 1 AND HIER_FD in (8702)
AND art_nr in (43848))
Union
(Select art_nr, MENG_STK as S03
FROM NW_ART@MMS_HK WHERE BESTAND_L = 1 AND HIER_FD in (8703)
AND art_nr in (43848));
The outcome is the following :
ART_NR S01
-------- ----
1|43848 742
2|43848 1357
3|43848 2172
I want to turn it into this:
ART_NR S01 S02 S03
-------- ---- ---- ----
1| 43848 742 1357 2172
我有 0 線索如何將其加入 1 行 3 列,我嘗試過:
選擇 S01、S02、S03..... 但它顯示了一個錯誤。
有誰能幫幫我嗎?
uj5u.com熱心網友回復:
你不需要工會。
SELECT
art_nr
, max(case when BESTAND_L = 1 AND HIER_FD in (8701) then MENG_STK end) as S01
, max(case when BESTAND_L = 1 AND HIER_FD in (8702) then MENG_STK end) as S02
, max(case when BESTAND_L = 1 AND HIER_FD in (8703) then MENG_STK end) as S03
FROM NW_ART@MMS_HK WHERE art_nr in (43848))
Group By art_nr;
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/327049.html
標籤:sql sql-server 变量 oracle-sqldeveloper
上一篇:無法從函式中運行find命令
