问题描述
SELECT t1.customerinformation.customerid AS CustomerId
FROM EndUserNotificationHistoryEvent t1
WHERE t1.operationType <> 'DELETE';
在上面的查询中,仅当表中存在 operationType 列时才应执行条件。如果在不需要条件的情况下不存在 operationType 列。
解决方法
对于此特定查询,您可以使用:
SELECT t1.customerInformation.customerid AS CustomerId
FROM EndUserNotificationHistoryEvent t1
WHERE t1.operationType <> 'DELETE' OR t1.operationType IS NULL;
向 where 子句添加 IS NULL
检查将有效关闭删除检查,如果列是 NULL
。
试试这个:
SELECT t1.customerInformation.customerid AS CustomerId
FROM EndUserNotificationHistoryEvent t1
WHERE (t1.operationType <> 'DELETE' OR t1.operationType IS NULL)
,
除了布尔运算,另一种方法是使用 COALESCE
如下:
SELECT T1.CUSTOMERINFORMATION.CUSTOMERID AS CUSTOMERID
FROM ENDUSERNOTIFICATIONHISTORYEVENT T1
WHERE COALESCE(T1.OPERATIONTYPE,'NOT DELETE') <> 'DELETE';
-- WHEN T1.OPERATIONTYPE IS NULL,CONDITION WILL BE ALWAYS TRUE