where句でcase文が使えますので、A,B,C
カラムをwhere句のcase文でご参照ください。
上記のようなアルゴリズムを導入するのに適したoracleでの文法はnvl
とgreatest
を併用して、Aがない時はBとCの大きい値を参照する方法です。
ただし質問文の条件ではBとCが同値の場合の挙動が記述されていませんので、要求に合わせた改修をお願いいたします。
select nvl(A, greatest(B, C)) as NVL_GREATEST,
case when A is null then
case when B > C then B
when B < C then C
else null -- この行はなくても同じ
end
else A
end CASE_NEST
from (select to_date('2019/01/01') as A, to_date('2019/11/02') as B, to_date('2019/11/03') as C from dual union all -- Aが存在
select null as A, to_date('2019/11/02') as B, to_date('2009/01/03') as C from dual union all -- Bが大きい
select null as A, to_date('2009/01/02') as B, to_date('2019/11/03') as C from dual union all -- Cが大きい
select null as A, to_date('2019/11/11') as B, to_date('2019/11/11') as C from dual -- BとCが同値
)
where sysdate > case when A is null then
case when B > C then B
when B < C then C
else null
end
else A
end
--where sysdate > nvl(A, greatest(B, C))