gpt4 book ai didi

sql - 如何选择列值为空的行?

转载 作者:行者123 更新时间:2023-11-29 11:15:20 25 4
gpt4 key购买 nike

考虑以下数据库表:

id      |  is_visible
________|_______________
1 | true
2 | false
3 | -- i.e. null

我想选择所有 is_visible = null 的行。我尝试了以下查询:

SELECT * FROM tab WHERE is_visible = null;     -- 0 results
SELECT * FROM tab WHERE is_visible <> true; -- only fields with false value
SELECT * FROM tab WHERE is_visible <> false; -- only fields with true

我在postgresql和sql server中试过了
如何选择 is_visible = null 的行?

最佳答案

在 Postgres 和 SQL 服务器中,

SELECT * FROM tab WHERE is_visible is null;

如果要选择列值不为 null 的行,则使用 is not null 运算符:

SELECT * FROM tab WHERE is_visible is not null;

关于sql - 如何选择列值为空的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com