gpt4 book ai didi

sql - 连接条件的案例陈述

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

您好,我想在 where 条件或一些类似的逻辑中使用 case 语句。我想在 tmp_collaboration 表中没有行时忽略 where 条件,并在表中有一些行时使用条件。

Select clbid from tmp_collaboration;

select customer_id, product_id ,clbid
from customers c
where hdr_id = 10
and clbid in (select clbid from tmp_collaboration)
and status = 'y';

最佳答案

这是你想要的吗?

select customer_id, product_id ,clbid 
from customers c
where hdr_id = 10 and status = 'y' and
(clbid in (select clbid from tmp_collaboration) or
not exists (select 1 from tmp_collaboration)
);

关于sql - 连接条件的案例陈述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52428177/

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