sql - WHERE 子句中的 CASE 表达式用于不同和
问题描述
我可以使用 case 表达式来构建这样的位置吗?
select *
from table
where
case
when x=y then z= j and t=v
when x=k then q= p and s=l
end
;
我需要根据 x 变量的值更改 where 子句。
解决方案
使用or
:
select *
from table
where (x = y and z = j and t = v) or (x = k and q = p and s = l);
推荐阅读
- java - 无法检查 JDBC 自动提交模式,连接已关闭错误
- flutter - 如何在颤动的Listview中显示字符串列表
- amazon-web-services - 如何根据条件在 terraform 中动态替换变量的值
- javascript - MomentJS inBetween 总是返回 false
- php - php laravel 多次为表创建模型实例
- php - 允许客户在 WooCommerce 中设置产品价格并通过某些验证添加到购物车
- wordpress - Elementor wordpress - 第一部分在移动设备中不可见
- azure - Azure Function App 中的 Task.Run()
- python - Python Pandas 交换列值
- c++ - 如何读取运行 QProcess 的输出并将特定数据保存到变量?