【发布时间】:2017-03-30 11:37:31
【问题描述】:
如果第一列等于特定值,是否可以在不同列上加入表。
见下文:
表A
.----+-----------------.
| ID | Name |
+----+-----------------+
| 1 | Name goes here1 |
| 2 | Name goes here2 |
| 3 | Name goes here3 |
| 4 | Name goes here4 |
.----+-----------------+
表B
.----+-----------------+-----------------.
| ID | id1 | id2 |
+----+-----------------+-----------------+
| 1 | ID goes here | ID goes here |
| 2 | ID goes here | ID goes here |
| 3 | ID goes here | ID goes here |
| 4 | ID goes here | ID goes here |
.----+-----------------+-----------------.
例如,我想加入 tableA ON tableA.ID = tableB.id1 UNLESS tableB.id1 = x THEN JOIN ON tableB.id2
【问题讨论】:
-
能否请您添加所需的输出也有问题?到时候帮到你就很容易了。
-
x 可以为空吗??
-
ON (tableA.ID = tableB.id1 AND tableB.id1 <> x) OR (tableA.ID = tableB.id2)