当前位置: 首页 > news >正文

做直播网站需要手续宁波seo外包推广排名

做直播网站需要手续,宁波seo外包推广排名,免费制作软件官网,英语培训网站源码参考文章: HiveSql一天一个小技巧:如何不使用union all 进行列转行_不 union all-CSDN博客文章浏览阅读881次,点赞5次,收藏10次。本文给出一种不使用传统UNION ALL方法进行 行转列的方法,其中方法一采用了concat_wsposexplode()方…

参考文章:

HiveSql一天一个小技巧:如何不使用union all 进行列转行_不 union all-CSDN博客文章浏览阅读881次,点赞5次,收藏10次。本文给出一种不使用传统UNION ALL方法进行 行转列的方法,其中方法一采用了concat_ws+posexplode()方法,利用posexplode的位置索引实现key-value之间的一一对应,方法二采用explode()+case when的方法,利用case when 进行转换实现key-value之间的一一对应。_不 union allhttps://blog.csdn.net/godlovedaniel/article/details/125019658  列转行(UDTF函数:炸裂:一进多出)

0  需求分析

    

1 数据准备

create table if not exists table22
(id      int comment '用户id',name    string comment '姓名',age     string comment '年纪',gender  string comment '性别');
insert overwrite table table22
values (1, 'mimi','11','0'),(2, 'geg','32','1');

2 数据分析

 方式一:使用union all 的方式行转列

selectid,'name' as type,name   as value
from table22
union all
selectid,'age' as type,age   as value
from table22
union all
selectid,'gender' as type,gender   as value
from table22
order by id;

ps: 使用union all 方式需要注意:上下两段逻辑,对应字段的类型要一致,字段名称也必须一致

方式二:不使用union all 方法,采用 concat_ws() + posexplode()方法,利用pos的位置索引进行一一对应。(where pos1 = pos2)

完整的代码如下:

selectid,type,value
from (selectt1.id,tmp1.pos1,tmp1.item1 as value,tmp2.pos2,tmp2.item2 as typefrom (selectid,concat_ws(',', name, age, gender) as value,array('name', 'age', 'gender')    as typefrom table22) t1lateral view posexplode(split(value, ',')) tmp1 as pos1, item1lateral view posexplode(type) tmp2 as pos2, item2) t2
where pos1 = pos2;

上述的SQL简化如下:

selectid,item2 as type,item1 as value
from table22lateral view posexplode(split(concat_ws(',', name, age, gender), ',')) tmp1 as pos1, item1lateral view posexplode(array('name', 'age', 'gender')) tmp2 as pos2, item2
where tmp1.pos1 = tmp2.pos2;

    explode及posexolode炸裂函数的详细用法见文章:

HiveSQL题——炸裂函数(explode/posexplode)_hive exolode-CSDN博客文章浏览阅读1.2k次,点赞28次,收藏13次。HiveSQL题——炸裂函数(explode/posexplode)_hive exolodehttps://blog.csdn.net/SHWAITME/article/details/135941286?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170753932316800192292655%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=170753932316800192292655&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-2-135941286-null-null.nonecase&utm_term=%E7%82%B8%E8%A3%82%E5%93%88%E6%95%B0&spm=1018.2226.3001.4450

方式三:采用explode() + case when 方法,先用array()函数将字段封装,再利用case when与字段值进行匹配。

selectid,tmp1.type,case tmp1.typewhen 'name' then namewhen 'age' then agewhen 'gender' then genderelse null end as value
from table22lateral view explode(array('name', 'age', 'gender')) tmp1 as type

3 小结

   上述案例采用了多种【行转列】的方法,除了常规的union all 上下拼接,还可以利用 concat_ws + posexplode() 结合方式,利用炸裂函数posexplode的下角标pos来实现pos -value的一一对应; 另外还可以利用 explode()+ case when结合方式,用case when进行条件判断,一一匹配。

http://www.yidumall.com/news/26946.html

相关文章:

  • 怎么做外贸网站优化网络项目怎么推广
  • 企业网站的建立和推广黄冈网站推广厂家
  • 做精彩网站分析的方向是怎么去做网络推广
  • 与国外公司合作网站建设上海公司全网品牌推广
  • 网站建设电商网站建设黄页视频
  • 一个网站怎么做pc和移动端谷歌浏览器app下载安装
  • 网上学习网站有哪些今日军事新闻最新消息新闻
  • vc6.0做网站网站及搜索引擎优化建议
  • 公司怎么注册自己的网站做推广的公司
  • 武汉 网站seo建站优化
  • 电子商务网站建设与管理基础应用商店下载安装
  • 博山政府网站建设哪家专业南京百度网站推广
  • 文山网站建设求职简历站外推广渠道有哪些
  • 内容型网站神马搜索seo优化排名
  • 想在网上做外卖 上什么网站好sem代运营托管公司
  • 网站后台怎么做外部链接怎样把自己的产品放到网上销售
  • 卖东西怎么做网站爱站网备案查询
  • 做网站付款会有凭证吗爱奇艺科技有限公司
  • 西班牙语网站建设网络营销的四大特点
  • 手机优化电池充电要开吗seo排名优化联系13火星软件
  • 海宏集团网站建设seo网站关键词优化机构
  • 公司网站开发哪家好南京seo推广优化
  • 网站设计方案公司百度seo优化价格
  • web网站开发德 参考文献软件推广怎么赚钱
  • o2o网站建设行情网站seo外链
  • 建筑公司年度工作总结报告秦洁婷seo博客
  • 怎样投网站广告网络培训研修总结
  • 深圳网站建设培训班草莓永久地域网名入2022
  • 西安网站设计公司哪家好互联网营销师培训学校
  • 成都专业做网站的公司有哪些新产品推广