我有一个以下场景。您能否更正以下查询..
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;
如果我理解正确,你可以用OR
和AND
代替CASE WHEN
你可以试试这个。
我有一个关于acad_plan is null
的小问题,您想检查哪个acad_plan
l.acad_plan
或m.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
。使用AND
和OR
和括号。
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)