将分散在多行的数据,拼接成一个新的列
|
|||||||||||||||||||||||||||
经典案例: 将血型和星座都相同的人拼接到一起:
代码实现: select info,concat_ws('|',collect_set(name)) from ( select name,concat_ws(',',constellation,blood_type) info from tb1 )t1 group by info; |
将一个数据类型为array的列中的元素拆分为多行
select movie,cate from movie_info lateral view explode(category) t1 as cate; |
|||||||||||||||||||||||||
经典案例:
tb1--->tb2: selelct city, concat_ws(',',colect_set(loc)) locs from tb1 group by city; ---------------------------------------------------------------- tb2--->tb1: select city, loc from tb2 lateral view explode(split(locs,',')) tmp as loc; |