SQL加入Table/映射

SQL JOIN Table/ mapping

你好, 我有 2 个简单的表,我必须进行一个映射数据的查询,如下例所示。我使用甲骨文 SQL 。请帮助我:)

Table一个

ID | A1 | A2 | A3 | Year
---+----+----+----+-----
1  |3   | 5  | 7  | 2000
2  |4   |    | 5  | 2001

Table 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

使用不同的别名多次加入btable

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