直升机, 我有2个简单的表,我必须做一个映射数据的查询作为下面的例子。我使用Oracle SQL。请帮帮我:)。
表A
ID | A1 | A2 | A3 | Year
---+----+----+----+-----
1 |3 | 5 | 7 | 2000
2 |4 | | 5 | 2001
表B
Atribute | Values
---------+------------
3 | Apple
4 | Lime
5 | Pineapple
6 | Apricot
7 | Mango
结果
ID | A1 | A2 | A3 | Year
----+-------+------------+------------+-------
1 | Apple | Pineapple | Mango | 2000
2 | Lime | | Pineapple | 2001
答案 0 :(得分:1)
使用不同的别名
多次加入b
表
select a.id, a.year,
b1.values as a1,
b2.values as a2,
b3.values as a3
from a
left join b b1 on a.a1 = b1.attribute
left join b b2 on a.a2 = b2.attribute
left join b b3 on a.a3 = b3.attribute