SQL Case语句在以下情况下不为null:
示例:
SELECT
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE default_result
END
FROM table_name;
示例:
SELECT column1, column2,
CASE
WHEN column1 > column2 THEN 'Column1 is greater'
ELSE 'Column2 is greater'
END AS comparison_result
FROM table_name;
示例:
SELECT column1, column2,
(CASE
WHEN column1 > column2 THEN 'Column1 is greater'
ELSE 'Column2 is greater'
END) AS comparison_result
FROM table_name;
需要注意的是,Case语句的结果类型取决于其结果表达式的数据类型,如果结果表达式的数据类型是可为null的,则Case语句的结果也可以为null。
领取专属 10元无门槛券
手把手带您无忧上云