如何在 SQL 钻取查询中的 table 中存在检查列
How to a check column exits in a table in SQL drill query
SELECT t1.customerInformation.customerid AS CustomerId
FROM EndUserNotificationHistoryEvent t1
WHERE t1.operationType <> 'DELETE';
在上面的查询中,仅当 table 中存在 operationType 列时才应执行 where 条件。如果在不需要条件的地方不存在 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
SELECT t1.customerInformation.customerid AS CustomerId
FROM EndUserNotificationHistoryEvent t1
WHERE t1.operationType <> 'DELETE';
在上面的查询中,仅当 table 中存在 operationType 列时才应执行 where 条件。如果在不需要条件的地方不存在 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