开发者

Boolean returning case

开发者 https://www.devze.com 2023-04-06 01:15 出处:网络
I need to join two tables. If b column is empty then the join will be done on c column. If not the join will be on b column.

I need to join two tables. If b column is empty then the join will be done on c column. If not the join will be on b column.

This works as I need. But I suspect I'm missing something as it looks a bit convoluted for what it does:

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
开发者_开发知识库

Am I missing something?


ON (a.b = '' AND t.c = a.c) OR (a.b <> '' AND t.b = a.b)
0

精彩评论

暂无评论...
验证码 换一张
取 消