gpt4 book ai didi

sql - 如何处理postgresql日期字段中的空值

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

我必须忽略日期列中有 null 的行。我该怎么做?

select s."SR Closed Date"::date,
s."Service Request Number",
a."Activity ID"
from sr_data_master s,
activity_master a
where s."Service Request Number" = a."Service Request Number"
and a."Service Request Number" is not null
and a."Service Tag" is not null
and a."Activity ID" is not null
and s."SR Closed Date"::date is not NULL
group by s."Service Request Number",
s."SR Closed Date"::date,
a."Activity ID";

我收到错误:

 invalid input syntax for type date: "NULL" 

最佳答案

错误消息表明您的“日期”列(显然实际上不是日期列)包含字符串常量 'NULL' 而不是真正的 null值(因为将真正的 null 值转换为 date 值没有问题)。

您可以使用以下条件来排除这些行:

and s."SR Closed Date" <> 'NULL'

但解决此问题的正确方法是将日期值存储在 DATE 列中。那么您就不需要转换,也不能存储无效的日期值。

关于sql - 如何处理postgresql日期字段中的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52330834/

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