首页 > 解决方案 > 自定义列上的 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 中实现这一点。

提前致谢

标签: sqldatabaseoracleoracle11g

解决方案


我怀疑你只是想要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'; 

推荐阅读