Sql server 布尔返回格
我需要把两张桌子连接起来。如果b列为空,则连接将在c列上完成。如果不是,则连接将位于b列上 这是我需要的。但我怀疑我遗漏了什么,因为它的功能看起来有点复杂:Sql server 布尔返回格,sql-server,sql-server-2008,boolean,case,Sql Server,Sql Server 2008,Boolean,Case,我需要把两张桌子连接起来。如果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
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
我遗漏了什么吗?关于(a.b=''和t.c=a.c)或(a.b''和t.b=a.b)
ON (a.b = '' AND t.c = a.c) OR (a.b <> '' AND t.b = a.b)
ON(a.b=''和t.c=a.c)或(a.b''和t.b=a.b)