我在蜂巢中有2张桌子: 第一个表(表1):
id val1 val2 val3
1 NULL NULL NULL
1 NULL NULL NULL
1 NULL NULL NULL
1 NULL NULL NULL
第二张表(表2):
id val row_number
1 x 1
1 y 2
1 z 3
我想加入表格,使最终结果像:
id val1 val2 val3
1 x y z
1 x y z
1 x y z
1 x y z
可以肯定的是,在表2中,对于特定的ID,将有3条记录,并且每个值(列“ val”)都必须加载到该ID的所有行的val1,val2,val3列中在表1中。
答案 0 :(得分:1)
您似乎想要:
select t1.id, t21.val as val1, t22.val as val2, t23.val as val3
from t1 join
t2 t21
on t21.id = t1.id and t21.row_number = 1 join
t2 t22
on t22.id = t1.id and t22.row_number = 2 join
t2 t23
on t23.id = t1.id and t23.row_number = 3;