简体   繁体   English

SQL在分支条件下联接表

[英]SQL join a table on a branching condition

I'm trying to perform an SQL join "with a twist", something like this: 我正在尝试执行“带有扭曲”的SQL连接,如下所示:

SELECT *
FROM a
JOIN b ON /* a.type == 'any' ? b.id IS NULL : b.id = a.id */

where the comment is written in C-like syntax. 注释以类似C的语法编写。 How can I express what I want in SQL? 如何表达我想要的SQL? (Preferably ANSI, but specific to Oracle Database is fine too.) (最好是ANSI,但也可以特定于Oracle数据库。)

SELECT *
FROM a
JOIN b ON (a.type  = 'any' AND b.id IS NULL) 
       OR (a.type <> 'any' AND b.id = a.id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM