是否有高效對此示例的替代SQL?我不想使用WITH ... AS,這是主要的標準SQL - 替代WITH ... AS
WITH TEMP_TABLE AS (
SELECT status, COUNT(1) as total FROM XYZ GROUP BY status
)
SELECT
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'A'),0) AS A_COUNT ,
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'B'),0) AS B_COUNT ,
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'C'),0) AS C_COUNT ,
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'D'),0) AS D_COUNT ,
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'E'),0) AS E_COUNT ,
NVL((SELECT TOTAL FROM TEMP_TABLE WHERE STATUS = 'F'),0) AS F_COUNT
FROM DUAL;
我讀到類似的問題,但他們使用其他DDL的東西,我只想要一個基本的SQL語句。
所以,你想知道如何擺脫[CTE(HTTP的://計算器.com/questions/38775056/creating-a-cte-in-oracle)從你的陳述? CTE的功能非常強大和高效......你爲什麼想要擺脫它? – SQLMason
是的,我知道並喜歡它,但理由是騾子平臺不支持它,至少不是一個實際的方式。請檢查此http://stackoverflow.com/a/36877716/2815227 – mCeviker
感謝您的解釋,我不明白 – SQLMason