在 where 子句预言机中切换大小写



我有一个以下场景。您能否更正以下查询..

where l.au=m.acad_group
and l.acad_prog = m.acad_prog
case when acad_plan is not null then and l.acad_plan = m.acad_plan else and 0=0 
end case
case when l.acad_sub_plan is not null then and l.acad_sub_plan=m.acad_sub_plan 
else and 0=0 end case;

如果我理解正确,你可以用ORAND代替CASE WHEN

你可以试试这个。

我有一个关于acad_plan is null的小问题,您想检查哪个acad_planl.acad_planm.acad_plan

where l.au=m.acad_group 
AND l.acad_prog = m.acad_prog
AND (acad_plan is null  OR( acad_plan is not null AND l.acad_plan = m.acad_plan))
AND (l.acad_sub_plan is null  OR( l.acad_sub_plan  is not null AND l.acad_sub_plan=m.acad_sub_plan))

不要在WHERE子句中使用CASE WHEN。使用ANDOR和括号。

where l.au = m.acad_group
and l.acad_prog = m.acad_prog
and (and l.acad_plan = m.acad_plan or l.acad_plan is null)
and (and l.acad_sub_plan = m.acad_sub_plan or l.acad_sub_plan is null)

最新更新