小工具知识网

当前位置: 首页 > 行业知识 > 头歌平台云计算实验

行业知识

头歌平台云计算实验

2026-12-05 04:01:17 来源:互联网转载

云计算

  • Hive综合应用案例——用户学历查询
    • 1 查询每一个用户从出生到现在的总天数
    • 2 同一个地区相同的教育程度的最高收入
    • 3 统计各级学历所占总人数百分比

      其他部分答案在B站工房 https://gf.bilibili.com/item/detail/1105242061

      Hive综合应用案例——用户学历查询

      1 查询每一个用户从出生到现在的总天数

      ---------- 禁止修改 ---------- drop database if exists mydb cascade;---------- 禁止修改 -------------------- begin -------------创建mydb数据库create database if not exists mydb;---使用mydb数据库use mydb;---创建表usercreate table usertab(    id string,    sex string,    time string,    education string,    occupation string,    income string,    area string,    desired_area string,    city_countryside string)row format delimited fields terminated by ',';---导入数据:/root/data.txtload data local inpath '/root/data.txt' into table usertab;--查询每一个用户从出生到2019-06-10的总天数select id, datediff('2019-06-10',regexp_replace(time, '/', '-')) from usertab;

      2 同一个地区相同的教育程度的最高收入

      ---------- 禁止修改 ---------- drop database if exists mydb cascade;---------- 禁止修改 -------------------- begin ------------创建mydb数据库create database if not exists mydb;---使用mydb数据库use mydb;---创建表usercreate table usertab1(    id int,    sex string,    time string,    education string,    occupation string,    income string,    area string,    desired_area string,    city_countryside string)row format delimited fields terminated by ',';---导入数据:/root/data.txtload data local inpath '/root/data1.txt' into table usertab1;--同一个地区相同的教育程度的最高收入select area,education,incomefrom(    select area,education,income,    row_number() over(        partition by area, education order by income desc    ) as t1    from usertab1) as t2where t2.t1 = 1;---------- end ----------

      3 统计各级学历所占总人数百分比

      ---------- 禁止修改 ---------- drop database if exists mydb cascade; set hive.mapred.mode=nonstrict;---------- 禁止修改 -------------------- begin ------------创建mydb数据库create database if not exists mydb;---使用mydb数据库use mydb;---创建表usercreate table usertab2(    id int,    sex string,    time string,    education string,    occupation string,    income string,    area string,    desired_area string,    city_countryside string)row format delimited fields terminated by ',';---导入数据:/root/data.txtload data local inpath '/root/data.txt' into table usertab2;--统计各级学历所占总人数百分比(对结果保留两位小数)select concat(round(t1.cnted * 100 / t2.cnt, 2),'%'), t1.educationfrom    (        select count(*) as cnted,education        from usertab2        group by education    ) as t1,    (        select count(*) as cnt from usertab2    ) as t2order by t1.education;---------- end ----------

上一篇:奥维云服务器怎么开通?

下一篇:【Java】IDEA中的JFormDesigner使用教程