我正在通过 Oracle DB 使用 iReport 创建报告。我必须根据这样的条件选择一些值:
AND EXISTS (SELECT 1 FROM TABLE_1 WHERE x = y)
OR EXISTS (SELECT 1 FROM TABLE_2 WHERE z = y)
只有当第一个为假时才可以执行第二个 EXISTS 吗?
尝试在括号中使用您的条件:
AND (
EXISTS (SELECT 1 FROM TABLE_1 WHERE x = y)
OR EXISTS (SELECT 1 FROM TABLE_2 WHERE z = y)
)
使用案例
where
...
AND 1 = case
when EXISTS (SELECT 1 FROM TABLE_1 WHERE x = y) then 1
when EXISTS (SELECT 1 FROM TABLE_2 WHERE z = y) then 1
else 0
end
AND (case when (SELECT count(*) FROM TABLE_1 WHERE x = y) > 0 then true
when (SELECT count(*) FROM TABLE_2 WHERE z = y) > 0 then true
else false end)