当我运行 sql query 时,如;
Select
F1 as name,
F2 as phone
from Table where condition = true
如果F2 = 0
我需要将该字段设为No Phone Number
而不是null
或0
答案 0 :(得分:7)
您可以使用CASE语句执行此操作:
SELECT
CASE WHEN F2 = '0' THEN '(No Phone Number)' ELSE F2 END AS Phone
...
答案 1 :(得分:1)
SELECT
CASE WHEN F2 = '0' OR F2 IS NULL THEN '(No Phone Number)' ELSE F2 END AS Phone
答案 2 :(得分:1)
您需要使用CASE
作为;
SELECT
F1 As name,
CASE WHEN F2 IS NULL OR F2 = '0' THEN 'No Phone Number' ELSE F2 END As phone
FROM Table
WHERE condition = 'true'