gpt4 book ai didi

sql - 如何在 SQL Server 中编写此条件 where 子句?

转载 作者:行者123 更新时间:2023-12-01 13:47:36 25 4
gpt4 key购买 nike

您好,我有以下类型的查询:

Select a,b from tab1 whre tab1.id in 
(Select id from tab2 where x=1 and y=2 and z>getdate())

现在 z 是 tab2 中的一个日期时间列,它是可以为 null 的列。所以我想要检查 z > getdate() 只有当它不为 null 时。勾选Conditional WHERE clause in SQL Server但不能准确地做到这一点。基本上我不希望在上面的查询中检查“z”列,如果它在 tab2 中为 null。

提前致谢。

最佳答案

你的意思是:

Select a,b from tab1 where tab1.id in 
(Select id from tab2 where x=1 and y=2 and (z is null or (z is not null and z>getdate())))

关于sql - 如何在 SQL Server 中编写此条件 where 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34719143/

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