大家好,喜欢Bigdata的阿尼亚来了!希望大家会喜欢阿尼亚的文章!!哇酷哇酷!!!

本次为师傅们带来的是“红亚杯”常用数据分析Hive SQL应用专题赛——满分解析系列的第③期,是“Hive专题赛(2)”篇章哦!

第①期完整赛题、第②期Hive专题赛(1)的链接在下面,师傅们想看完整赛题、Hive专题赛(1)的请安心享用:

【阿尼亚喜欢BigData】“红亚杯”常用数据分析Hive SQL应用专题赛——满分解析①_爱波吉的阿尼亚的博客-CSDN博客

【阿尼亚喜欢BigData】“红亚杯”常用数据分析Hive SQL应用专题赛——满分解析②_爱波吉的阿尼亚的博客-CSDN博客

目录

Hive专题赛(2)

TopK、排序数据分析:

1.统计person表中各种族(race)的总人数,并按照总人数倒序排序,将结果写入本地/root/person06/。

2.统计不同职业薪资大于50K的总人数,且人数按照降序排序取Top3,将结果写入本地/root/person07/。

3.计算较高收入(收入等于大于50K的为高收入)人群占整体数据的比例(保留两位小数),注意:设置支持笛卡尔积参考步骤说明,将结果写入本地/root/person08/。

Hive DDL基础操作:

1.在person数据库下创建student内部表(表结构参考步骤描述),并指定以制表符“\t”分隔;

2.使用alter语句修改student内部表结构新增一列字段名称为“address”,类型为“string”;

3.使用drop语句删除student内部表。


Hive专题赛(2)

TopK、排序数据分析:

TopK、排序数据分析

考核条件如下:

1.统计person表中各种族(race)的总人数,并按照总人数倒序排序,将结果写入本地/root/person06/。

操作环境: hive专题赛环境

insert overwrite local directory '/root/person06'
row format delimited fields terminated by '\t'
select race,count(*) as c from person group by race order by c desc;

2.统计不同职业薪资大于50K的总人数,且人数按照降序排序取Top3,将结果写入本地/root/person07/。

操作环境: hive专题赛环境

insert overwrite local directory '/root/person07/'
row format delimited fields terminated by '\t'
select occupation,count(*) as s from (select * from person where income=">50K") t1 group by occupation order by s desc limit 3;

3.计算较高收入(收入等于大于50K的为高收入)人群占整体数据的比例(保留两位小数),注意:设置支持笛卡尔积参考步骤说明,将结果写入本地/root/person08/。

操作环境: hive专题赛环境

set hive.strict.checks.cartesian.product;         #查看当前是否支持笛卡尔积

set hive.strict.checks.cartesian.product=false;   #修改设定成为支持笛卡尔积
insert overwrite local directory '/root/person08/'
row format delimited fields terminated by '\t'
select round((t2.v/t4.s),2) from (select count(*) as v from person t1 where income=">50K" )t2 join (select count(*) as s from person t3) t4;

Hive DDL基础操作:

Hive DDL基础操作

考核条件如下:

1.在person数据库下创建student内部表(表结构参考步骤描述),并指定以制表符“\t”分隔;

操作环境: hive专题赛环境

create table if not exists student(id int,name string,age int,sex string)
row format delimited fields terminated by '\t';

2.使用alter语句修改student内部表结构新增一列字段名称为“address”,类型为“string”;

操作环境: hive专题赛环境

alter table student add columns(address string);

3.使用drop语句删除student内部表。

操作环境: hive专题赛环境

drop table if exists student; 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐