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