sql - 连接条件的 case 语句
问题描述
嗨,我想在 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)
);
推荐阅读
- python - SQL ALCHEMY - 如何返回 query(model).all() 作为值元组而不是模型实例
- c# - MVVMCross 通知 ViewModel Model 属性的变化
- azure - 我的 Azure Function 正在使用什么 dotnet 运行时版本?
- php - 来自 sql 的 PHP 3 多选查询
- css - 每当出现虚拟键盘时如何设置样式?
- svg - 如何使svg中的多边形响应(vw,vh)
- javascript - 如何渲染使用表单输入添加的数据?
- php - 在 MultiCell FPDF 中手动添加换行符
- java - 为什么 SSL 上下文不返回 TLSv1.2 的 SSLSession 信息?
- wordpress - Cloudflare CacheEverything:如何绕过 Wordpress 的登录用户管理栏?