問題描述
我在表中有一個 Status 列,它有 3 個值 - 'N/A'、'Single'、'Multiple'.某些行的狀態列具有 NULL
值.
I've a Status column in a table which has 3 values - 'N/A' , 'Single' ,'Multiple'. Some rows have a NULL
value for the Status column.
我需要提取 Status 不為空且不為N/A"的所有行.基本上,我需要狀態為單個"或多個"的所有行.
I need to pull up all the rows in which Status is not null and is not 'N/A'. Basically, I need all the rows whose status is "Single" or "Multiple".
我剛剛了解到 NULL 實際上等同于UNKNOWN".
I've been just reading up about NULL actually being equivalent to 'UNKNOWN'.
如果我說
SELECT *
FROM t_userstatus
WHERE status <> 'N/A'
我得到了結果(僅包含單個"或多個"的所有行).
I get the results (All rows containing "Single" or "Multiple" only).
我想知道的是,上面的 WHERE
子句是否總是排除具有 NULL 值的行?這是預期的行為嗎?
What I would like to know is that , does the above WHERE
clause always exclude the rows having NULL values?Is that the expected behaviour?
是什么導致即使我沒有明確指定它也會排除空行?
在我的查詢中,我是否必須明確說狀態 IS NOT NULL
?
In my query,do I have to explicitly say status IS NOT NULL
?
我對編程比較陌生,不勝感激.
I am relatively new to programming, any help is appreciated.
推薦答案
SQL 使用 三值邏輯:真、假、未知.與 null
的任何比較都會導致 unknown
.
SQL uses three-valued logic: true, false, and unknown. Any comparison to null
results in unknown
.
所以 null <>'N/A'
計算結果為 unknown
.由于 unknown
不正確,這意味著該行被排除在外.
So null <> 'N/A'
evaluates to unknown
. Since unknown
is not true, that means the row gets excluded.
這篇關于SQL 服務器查詢中的 NULL 值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!