0
我有表:動態JOIN條件
Tbl1
+----+------+
| id | type |
+----+------+
| 1 | 11 |
| 1 | 22 |
| 2 | * |
+----+------+
Tbl2
+----+------+------+
| id | type | name |
+----+------+------+
| 1 | 11 | AAA |
| 1 | 22 | BBB |
| 2 | 11 | CCC |
| 2 | 22 | DDD |
+----+------+------+
我想加入的ID和類型。但是,如果type ='*'我想要所有類型。 如何加入Tbl1和Tbl2來達到這個效果?
喜歡的東西:
SELECT a.* FROM Tbl2 a
INNER JOIN Tbl1 b ON a.id = b.id
AND a.type = b.type ?? (i want use case statement to achieve this result)
result
+----+------+------+
| id | type | name |
+----+------+------+
| 1 | 11 | AAA |
| 1 | 22 | BBB |
| 2 | 11 | CCC |
| 2 | 22 | DDD |
+----+------+------+
嘗試'... a.type = case when a.type ='*'then'*'else b.type end' – amdixon