hive习题一

hive习题一

1、原数据表时user和dpt表,请使用hql实现result表中的结果.
dpt表
dpt_id dpt_name
1 产品
2 技术
user_dpt表
user_id dpt_id
1 1
2 1
3 2
4 2
5 3
result表
user_id dpt_id dpt_name
1 1 产品
2 1 产品
3 2 技术
4 2 技术
5 3 其他部门
select b.user_id,b.dpt_id,nvl(a.dpt_name,‘其他部门’)from user_dpt b left outer join dpt a on a.dpt_id=b.dpt_id;

2、
t1表:
order_id order_type order_time
111 N 10:00
111 A 10:05
111 B 10:10

是用hql获取结果如下:
order_id order_type_1 order_type_2 order_time_1 order_time_2
111 N A 10:00 10:05
111 A B 10:05 10:10

select * from(
select
id,
type,
lead(type) over (partition by id order by time) a,
time,
lead(time) over (partition by id order by time) b
from order_table) c where c.type<>‘B’

3、现有一张数据库表student表:
Name Course Score
Huangbo Math 81
Huangbo English 87
Huangbo Computer 57
Xuzheng Math 89
Xuzheng English 92
Xuzheng Computer 83
Wangbaoqiang Math 78
Wangbaoqiang English 88
Wangbaoqiang Computer 90
Dengchao Math 88
Dengchao Computer 58
请求出:
1、用一条SQL语句查询出student表中每门课都大于80分的学生姓名
select b3.name from
(
select b1.name,t-a s from
(select name,count(1) t from student group by name) b1 join
(select name,count(1) a from student where score>80 group by name) b2 on
b1.name=b2.name
) b3 where b3.s=0;
2、用一条SQL语句查询出student表中有不及格成绩的学生姓名
select name a from student where score>60 group by name;

4、现在有一份数据mingxing_favor表:
Id Name Age Favor
1 Huangbo 33 A,B,C,D,E
2 Xuzheng 44 B,C
3 Wangbaoqiang 55 C,D,E
4 Fanbingbing 32 A,B,D
求出每种爱好中年龄最大的人,如果有相同的年龄,请并列显示
select * from
(
select *,
dense_rank()over(partition by l1 order by age desc) l2
from
(select name,age,l1 from favor lateral view explode(split(favor,’,’)) b1 as l1) b2
)b3 where l2=1;

5、ABC三个hive表 每个表中都只有一列int类型且列名相同,求三个表中互不重复的数
a.txt b.txt c.txt
1 2 1
2 3 2
3 11 3
4 12 11
5 14 5
6 15 6
7 16 7
8 18 8
9 35 20
6 30
7 40
8

select id,count(id) as c1 from
(select id from a
union all
select id from b
union all
select id from c) t_union
group by id having c1=1;**

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值