SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
解決方法: 在CASE WHEN語句的末尾添加END關鍵字,如下所示:
SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
END
SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
ELSE result_3
END
解決方法: 確保CASE WHEN語句中的條件完整且沒有重復,如下所示:
SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
ELSE result_3
END
SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
END
解決方法: 為CASE WHEN語句添加ELSE子句,以處理未匹配的條件,如下所示:
SELECT
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
ELSE result_3
END
SELECT
CASE
WHEN column_1 = 'value' THEN result_1
WHEN column_2 = 1 THEN result_2
ELSE result_3
END
解決方法: 確保CASE WHEN語句中使用的條件和結果都是合適的數據類型,如下所示:
SELECT
CASE
WHEN column_1 = 'value' THEN result_1
WHEN column_2 = '1' THEN result_2
ELSE result_3
END
SELECT
CASE
WHEN column_1 = 'value' THEN result_1
WHEN column_2 = 'value' result_2
ELSE result_3
END
解決方法: 確保CASE WHEN語句中的條件表達式使用了正確的語法,如下所示:
SELECT
CASE
WHEN column_1 = 'value' THEN result_1
WHEN column_2 = 'value' THEN result_2
ELSE result_3
END