在特定情况下,我有一个填充了 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 检查了这种情况。
有两个表Document
和DocumentPos
。在Document
有列GUID
和在DocumentPos
是DocumentGUID
指表的列Document
。
我想让每一行都在
DocumentPos
它DocumentGUID
现在的行中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
。这DocumentGUID
是NOT IN
表Document
作为GUID
.
但select * from Document where GUID = 'B479BCB72334424DAC1B7CC26880DAB8'
返回 0 行。
我想像这样构建查询,因为它应该成为一个DELETE …
如果 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
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?
我的表中有两列。表名是用inner join和group by构造的,我们称这个表为Joined
。它有两列Present
和Score
。如果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 语句:
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-null ×6
sql ×5
postgresql ×3
case ×1
coalesce ×1
database ×1
sql-delete ×1
sql-server ×1
sqlite ×1
string ×1
subquery ×1