大数据之Hive:子查询之not in

1.前言:

我们知道子查询可以放在from后,join后,where xx not in后,还可以直接放在select后,今天我们实战几个子查询之not in,来加深一下not in的使用;

2.实战

案例一:有这样一张stu_score表,字段有三个,分别是name 名字 course 课程 score 分数
需求:我们现在需要查出每门功课成绩都大于80分的学生的姓名

name course score 
张三 语文 81
张三 数学 75
张三 英语 70
李四 语文 76
李四 数学 90
李四 英语 75
王五 语文 81
王五 英语 90
王五 数学 100

实现:
方法一:

select distinct name from stu_score where name not in (select distinct name from stu_score where score < 80);

方法二:

select name from stu_score group by name having min(score)> 80;

案例二:有这样一张stu_info表,字段有四个,分别是num 编号 name 名字 course 课程 score 分数
需求:删除除了编号不同,其他都相同的学生溶于信息;

num  name  course score
1    张三    数学   60
2    李四    数学   89
3    王五    英语   80
4    张三    数学   60

实现:
方法一:

delete  stu_info where num not in (select min(num) from stu_info group by name,course,score );
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值