表A
ID | num |
1 | 2 |
1 | 3 |
1 | 4 |
2 | 6 |
2 | 8 |
表B
ID | num |
1 | 2,3,4 |
2 | 6,8 |
从表A变为表B:(concat_ws 合并函数 collect 收集)
select ID, concat_ws(',' , collect(num)) as num
from 表A
group by
ID
从表B变为表A:(explode()、split() 和 LATERAL VIEW 函数 的使用)
select ID, num
from 表B
LATERAL VIEW explode(split(num, ',') adTable AS num