开发者

Boolean returning case

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜