通过子查询包含一个案例并排除它给出不同数量的数据

问题描述 投票:0回答:0

我正在尝试编写查询以确定某人是否未成年人。

select 
case when 
((select trunc((sysdate - to_date(customer.birthday)) / 365, 0) from dual) > 18)  then 'N' -- If the age is greater than 18, not a minor
else 'Y'
end as minor,
-- other columns.....
from database.customer cusomter

上面的查询给了我大约 100 个结果。 但是,当我像下面这样从我的查询中排除该子句时,它会给我大约 1000 个结果。

select 
customer.birthday,
-- other columns.....
from database.customer

我试图在 oracle 中查找 decode 和 case by 之间的区别,我的猜测是它与 oracle 处理空值的方式有关,但我不能真正指出它。 任何帮助,将不胜感激。谢谢!

oracle subquery decode
© www.soinside.com 2019 - 2024. All rights reserved.