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

怎么让学生在网站上做问卷调查门户网站设计与开发

怎么让学生在网站上做问卷调查,门户网站设计与开发,项目总结,麦当劳的网络营销方式目录 1.删除2.更新:3.行转列:4.列转行:5.分析函数:6.多维分析7.数据倾斜groupby:join: 掌握下面的技巧,你的SQL水平将有一个质的提升! 1.删除 正常hive删除操作基本都是覆盖原数据&…

目录

  • 1.删除
  • 2.更新:
  • 3.行转列:
  • 4.列转行:
  • 5.分析函数:
  • 6.多维分析
  • 7.数据倾斜
    • groupby:
    • join:

掌握下面的技巧,你的SQL水平将有一个质的提升!

1.删除

正常hive删除操作基本都是覆盖原数据;

insert overwrite tmp 
select * from tmp where id != '666';

2.更新:

更新也是覆盖操作;

insert overwrite tmp 
select id,label,if(id = '1' and label = 'grade','25',value) as value 
from tmp where id != '666';

3.行转列:

思路1:
先通过concat函数把多列数据拼接成一个长的字符串,分割符为逗号,再通过explode函数炸裂成多行,然后使用split函数根据分隔符进行切割;

-- Step03:最后将info的内容切分
select id,split(info,':')[0] as label,split(info,':')[1] as value
from 
(
-- Step01:先将数据拼接成“heit:180,weit:60,age:26”select id,concat('heit',':',height,',','weit',':',weight,',','age',':',age) as value from tmp
) as tmp
-- Step02:然后在借用explode函数将数据膨胀至多行
lateral view explode(split(value,',')) mytable as info;

思路2:使用union all函数,多段union

select id,'heit' as label,height as value
union all 
select id,'weit' as label,weight as value
union all 
select id,'age' as label,age as value

4.列转行:

思路1:多表join,进行关联

select 
tmp1.id as id,tmp1.value as height,tmp2.value as weight,tmp3.value as age 
from 
(select id,label,value from tmp2 where label = 'heit') as tmp1
join
on tmp1.id = tmp2.id
(select id,label,value from tmp2 where label = 'weit') as tmp2
join
on tmp1.id = tmp2.id
(select id,label,value from tmp2 where label = 'age') as tmp3
on tmp1.id = tmp3.id;

思路2:使用max(if) 或max(case when ),可以根据实际情况换成sum函数

select 
id,
max(case when label = 'heit' then value  end) as height,
max(case when label = 'weit' then value  end) as weight,
max(case when label = 'age' then value  end) as age 
from tmp2 
group by
id;

思路3:map的思想,先拼接成map的形式,再取下标

select
id,tmpmap['height'] as height,tmpmap['weight'] as weight,tmpmap['age'] as age
from 
(select id,str_to_map(concat_ws(',',collect_set(concat(label,':',value))),',',':') as tmpmap  from tmp2 group by id
) as tmp1;

5.分析函数:

select id,label,value,lead(value,1,0)over(partition by id order by label) as lead,lag(value,1,999)over(partition by id order by label) as lag,first_value(value)over(partition by id order by label) as first_value,last_value(value)over(partition by id order by label) as last_value
from tmp;
select id,label,value,row_number()over(partition by id order by value) as row_number,rank()over(partition by id order by value) as rank,dense_rank()over(partition by id order by value) as dense_rank
from tmp;

6.多维分析

select col1,col2,col3,count(1),Grouping__ID 
from tmp 
group by col1,col2,col3
grouping sets(col1,col2,col3,(col1,col2),(col1,col3),(col2,col3),())
select col1,col2,col3,count(1),Grouping__ID 
from tmp 
group by col1,col2,col3
with cube;

7.数据倾斜

groupby:

select label,sum(cnt) as all from 
(select rd,label,sum(1) as cnt from (select id,label,round(rand(),2) as rd,value from tmp1) as tmpgroup by rd,label
) as tmp
group by label;

join:

select label,sum(value) as all from 
(select rd,label,sum(value) as cnt from(select tmp1.rd as rd,tmp1.label as label,tmp1.value*tmp2.value as value from (select id,round(rand(),1) as rd,label,value from tmp1) as tmp1join(select id,rd,label,value from tmp2lateral view explode(split('0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9',',')) mytable as rd) as tmp2on tmp1.rd = tmp2.rd and tmp1.label = tmp2.label) as tmp1group by rd,label
) as tmp1
group by label;
http://www.yayakq.cn/news/975838/

相关文章:

  • 企业没有网站怎样做推广方案现在流行的网站开发
  • 郑州中小企业网站制作二类电商用网站怎么做H5页面
  • 厦门网站建设公司哪家好WordPress支持多少文章
  • 网站建设的维护宁波模板开发建站
  • 企业做网站需要什么条件莱芜网站优化怎么做
  • 企业不建立网站吗wordpress调用特色
  • 济南英文网站建设深圳品牌网站制作平台
  • 类似于wordpress的网站吗六安seo地址
  • 三九集团如何进行网站建设成都网站创建
  • 荣县规划和建设局网站是想建个网站 用本地做服务器
  • seo优秀网站分析怎么做线上销售
  • 找公司做网站要注意什么问题展馆展厅设计
  • 黄冈免费网站推广平台汇总建设一个网站的一般过程
  • 怎样做百度推广网站wordpress旅游网模板
  • 无锡网站设计 众wordpress 用户信息
  • 网站建网站建设网站做文案图片上什么网站
  • 网站数据库设置权限如何制作网站导航
  • 网站建设与维护教学课件wordpress更改发布的文章
  • 官方网站想反应问题不弄应该怎么做做网站哪家南京做网站
  • 郑州品牌网站建设医疗器械经营许可证
  • 大理中小企业网站建设域名如何指向网站
  • 公司网站制作与推广外包如何加工资
  • 微商城网站建设平台合同海洋公司做网站推广
  • 精致的个人网站wordpress 模版 psd
  • 如何做360网站的排名构建网站的步骤
  • 网站建设与管理教学视频教程做统计图的网站
  • 临沂品牌网站推广南城网站建设公司
  • 模板手机网站建设价格明细表2021国内军事新闻大事件
  • asp服装商城网站源码天津重型网站建设风格
  • HTML怎么做网站目录罗田住房和城乡建设局网站