Clo*_*eto 1 sql-server boolean case sql-server-2008
我需要加入两个表.如果b列为空,则将在c列上完成连接.如果不是,则联接将在b列上.
这是我需要的.但是我怀疑我错过了一些东西,因为它看起来有点令人费解:
select *
from the_table t
inner join another_table a
on
case when a.b = '' then
case when t.c = a.c then 1 else 0 end
else
case when t.b = a.b then 1 else 0 end
end = 1
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?