Hive sql面试

select store,count(distinct uid) as uv from Visit group by store;

select * from Users order by age desc, total;

考点:列转行
select stage_someone, count(distinct UID) from LifeStage lateral view explode(split(stage,’,’)) LifeStage_tmp as stage_someone group by stage_someone;

select UID,concat_ws(‘,’,collect_set(stage)) as stages from LifeStage group by UID;
考点:行转列


拆解json字段
这个时候要配合一下get_json_object




最终,我们可以通过下面的句子,把这个json格式的一行数据,完全转换成二维表的方式展现
LATERAL VIEW explode(split(regexp_replace(regexp_replace(sale_info,’\\[\\{‘,”),’}]’,”),’},\\{‘))sale_info as sale_info_1;

6.这个面试题偏难,但毕竟有意思

或者用:
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/174243.html原文链接:https://javaforall.net
