select *
from table1
(case
when table1.ID=0 then ( join table2 on ...)
else ( join table3 on ...)
end)
...全文
382打赏收藏
请教高手,急急急!!!在线等
有三张表table1、table2、table3,如果table1.ID=0那么table1需要join table2,否则table1需要join table3,下面的语句总是提示"在关键字 'case' 附近有语法错误。"不知道为什么?请高手指教,在线等!! select * from table1 (case when table1.ID=0 then ( join table2 on ...) else ( join table3 on ...) end)
case不能这样用,必须改为:
select *
from table1 inner join table2 on ……
where table1.ID=0
union all
select *
from table1 inner join table3 on ……
where table1.ID<>0