我在SQL Server 2014中进行了简单的选择
SELECT COUNT(*)
FROM SignOffOperations_View
WHERE Company = 'ASUS' AND Submission_Id = 10 AND IsOperationPerformed <> 1
如果不包含在where子句中,可以选择表中的数据:IsOperationPerformed
Id Submission_Id Company IsOperationPerformed
12008 10 ASUS NULL
2527 10 ASUS NULL
因此,此查询的结果为0.我不明白为什么。
答案 0 :(得分:0)
A value of NULL indicates that the value is unknown. A value of NULL is different
from an empty or zero value. No two null values are equal. Comparisons between
two null values, or between a NULL and any other value, return unknown because the
value of each NULL is unknown.
Null values generally indicate data that is unknown, not applicable, or that the data
will be added later. For example, a customer's middle initial may not be known at the
time the customer places an order.[Source-msdn]
使用查询
SELECT COUNT(*)
FROM SignOffOperations_View
WHERE Company = 'ASUS' AND Submission_Id = 10
AND IsOperationPerformed IS NOT NULL
AND IsOperationPerformed <> 1
OR
SELECT COUNT(*)
FROM SignOffOperations_View
WHERE Company = 'ASUS' AND Submission_Id = 10 AND ISNULL(IsOperationPerformed,-1) <> 1
答案 1 :(得分:0)
SELECT COUNT(*)[Total Count]
FROM SignOffOperations_View
WHERE Company = 'ASUS' AND Submission_Id = 10
AND IsOperationPerformed IS NOT NULL
AND ISNULL(IsOperationPerformed,0) <> 1