如何在
mysql查询中编写一个案例,该案例检查特定列的null或0
CREATE TABLE tblConfirmationStatus (Confirm_Status TINY INT) INSERT INTO tblConfirmationStatus Confirm_Status VALUES (1),(0),(1),({null}),({null})
要求的输出
ConfirmStatus
Confirmed Not Confirmed Confirmed Not Confirmed Not Confirmed Confirmed Not Confirmed
0或Null – 未确认,1 – 确认
SELECT CASE Confirm_Status WHEN NULL OR 0 THEN 'Not Confirmed' ELSE 'Confirmed' END AS ConfirmStatus FROM tblConfirmationStatus;
CASE语句有两种选择 – 您发布的语句或:
SELECT CASE WHEN Confirm_Status IS NULL OR Confirm_Status = 0 THEN 'Not Confirmed' ELSE 'Confirmed' END AS ConfirmStatus
但你可以使用:
SELECT CASE WHEN Confirm_Status > 0 THEN 'Confirmed' ELSE 'Not Confirmed' END AS ConfirmStatus
NULL是缺少值,因此检查大于零的值应该归入与零相同的类别.