sql - 自定义列上的 Where 子句
问题描述
select c.base_id,case when c.type is not null then c.type else g.type end as type, c.function_id
from cust c
left join category cg on c.cat_id=cg.id
where c.type='privelleged'; --- where clause is not working as expected
我在上面的查询中遗漏了什么。 where 子句没有按预期工作。我需要在派生的“类型”列上应用 where 子句。我如何在 Oracle 中实现这一点。
提前致谢
解决方案
我怀疑你只是想要coalesce()
-- 在select
和中where
:
select c.base_id, coalesce(c.type, g.type) as type, c.function_id
from cust c left join
category cg
on c.cat_id = cg.id
where coalesce(c.type, g.type) = 'privileged';
推荐阅读
- python - Python - 在字符串中查找子字符串(代码不起作用)
- angular - 在“dd-mm-yyyy”中转换日期“Tue Sep 25 2018” [angular4]
- sqlite - 哪个结果集用于 fmdb 中的图像?
- visual-studio - 使用增量构建对文件 MSBuild 进行签名
- php - 我想更新表,我已经通过它的 id 跟踪了所有记录。点击编辑后,它在每个编辑链接上显示相同(第一个记录的数据)
- django - 具有 3 个外键的嵌套序列化程序。如何实现 GET 和 POST?
- sqlite - 将 sqlite 数据库导入 gnuplot
- excel - VBA 迭代方法调用
- ios - 即使在 ios 等 android 应用程序崩溃后重新加载应用程序
- c++ - libdl 在创建 QObject 时如何链接?从代码链接?