标签: sql-null

即使存在 NULL 值,SQL Count NULL 值为 0

在特定情况下,我有一个填充了 1070 个项目的数据库表,并且在该过程的某个时刻,我向其中添加了一个名为“Current_Status”的列。因此,所有项目都有一个初始为NULL的新字段。

该表用作队列,对于处理的每一行,我将“Current_Status”字段更新为“已处理”或“未处理”。

为了查看过程进行得如何,我使用以下查询计算了状态仍为NULL的剩余项目:

SELECT COUNT([Current_Status]) FROM Table_Name WHERE [Current_Status] IS NULL
Run Code Online (Sandbox Code Playgroud)

问题是,在前 1000 个项目之后,该查询执行的结果是0,即使我检查并使用SELECT * FROM Table_Name查询显示那里仍有一些状态为NULL 的行。

任何想法可能导致这种情况?

我使用 Azure Data Studio 1.4.5 检查了这种情况。

sql azure-sql-database sql-null

1
推荐指数
1
解决办法
1950
查看次数

具有 NOT IN 和 WHERE 关系的 SQL 查询与 GUID

有两个表DocumentDocumentPos。在Document有列GUID和在DocumentPosDocumentGUID指表的列Document

我想让每一行都在DocumentPosDocumentGUID现在的行中Documents' GUID

我有这个返回 0 行的查询:

select *
FROM             Document d,
                 DocumentPos dp
WHERE            d.GUID = dp.DocumentGUID
AND              dp.DocumentGUID NOT IN (
                 SELECT d.GUID
                 FROM Document
)
Run Code Online (Sandbox Code Playgroud)

但是当我执行select * from documentpos它时,例如返回一行DocumentGUID= B479BCB72334424DAC1B7CC26880DAB8。这DocumentGUIDNOT INDocument作为GUID.

select * from Document where GUID = 'B479BCB72334424DAC1B7CC26880DAB8'返回 0 行。

我想像这样构建查询,因为它应该成为一个DELETE …

sql sql-server subquery sql-delete sql-null

1
推荐指数
1
解决办法
419
查看次数

如果列为 NULL 或为空字符串,则 Postgresql 连接列并跳过列

如果 postgres 中的列为 NULL 或为空,我正在尝试连接多个列并跳过该列。例如:

SELECT CONCAT(coalesce('a',''),
        '|',coalesce('b',''),
        '|',coalesce(NULL,''),
        '|',coalesce('',''),
        '|',coalesce('',''),
        '|',coalesce('c','')) AS finalstring;
Run Code Online (Sandbox Code Playgroud)

输出 : a|b||||c

预期输出: a|b|c

sql database string postgresql sql-null

1
推荐指数
1
解决办法
240
查看次数

How do I use COALESCE to return 'N/A' when the value of a TIMESTAMP column is NULL?

Is it possible to use COALESCE (or any other way) to replace NULL values from a TIMESTAMP column with a string like 'N/A'?

In my SELECT statement I have a

CASE WHEN n.expiration_date::date IS NULL THEN 'N/A' ELSE n.expiration_date::date END
Run Code Online (Sandbox Code Playgroud)

When I try this, I get this error, which makes sense:

invalid input syntax for type date: "N/A"

I found this blog post too about this problem. Is there a way around it?

postgresql coalesce sql-timestamp sql-null

0
推荐指数
1
解决办法
129
查看次数

SQLITE - 如果一列为空,则另一列中的值为 0

我的表中有两列。表名是用inner join和group by构造的,我们称这个表为Joined。它有两列PresentScore。如果Present为 null,那么我想将 0 赋给该Score值。

+------------+--------+-------------+------------+--------+
| Student_Id | Course | ExamDate    |  Present   | Score  |
+------------+--------+-------------+------------+--------+
|       1    | Math   | 04/05/2020  | Yes        | 45     |
|       2    | Math   | 04/05/2020  | NULL       | 90     |
|       2    | Math   | 04/05/2020  | NULL       | 50     |                     
+------------+--------+-------------+------------+--------+
Run Code Online (Sandbox Code Playgroud)

我现在所拥有的是

SELECT DISTINCT StudentID ,Course, ExamDate, Present, Score
CASE Present ISNULL
Score = 0
END
    FROM Joined …
Run Code Online (Sandbox Code Playgroud)

sql sqlite case sql-null

0
推荐指数
1
解决办法
1134
查看次数

不相等的地方

我有以下 SQL 语句:

select s.conclusion, t.* from trip t 
JOIN triprequirementsmapping m ON m.tripid = t.trip_id
JOIN approvalsubmission s ON s.requested = m.corporatetravelrequesturi
where s.conclusion <> 'DISCONTINUED'
Run Code Online (Sandbox Code Playgroud)

s.conclusion对于此示例, 的值为 null。

问题

当我希望它返回一行时,此查询不返回任何行,因为s.conclusion不是DISCONTINUED

如何使用 WHERE 子句返回所有没有值为 的行DISCONTINUED

sql postgresql sql-null

-1
推荐指数
1
解决办法
33
查看次数