【hive】子查询
hive中是不支持子查询的
但是并不意味这不支持in 或者 not in
in 或者not in 后边是定值的话是支持的
但是接定制是可以的
例如
select id from table not in(1,2,3)
但是这种是不支持的
select id from table1 not in (
select id from table2 where col1 = ‘a’
)
我们需要用left join来实现
(1)把table1和table2符合条件的数据进行连接
select t1.id as id1,t2.id as id2 from table1 t1 left join(
select id from table2 where col1 = ‘a’
这时符合条件的table1条目连接的table2条目为null
(2)然后根据in 或者 not in来筛选数据
where
in: id2 is not null
not in: id2 is null
或者使用left semi-join来实现(不支持right semi-join)
left-semi join 返回左边表满足 on 条件的记录
select id from table1 t1 left semi join table2 t2
on t1.id = t2.id and t2.col1 != ‘a’
left-semin join 要比join更高效,因为对于左表中一条制定的记录在右边表一旦匹配到就停止右边表的匹配
【hive】子查询的更多相关文章
- hive 子查询特别分析
Hive只支持在FROM子句中使用子查询,子查询必须有名字,并且列必须唯一:SELECT ... FROM(subquery) name ... 确认下是否一定要求列必须唯一? 建表语句 ...
- Hive:子查询
Hive只支持在FROM子句中使用子查询,子查询必须有名字,并且列必须唯一:SELECT ... FROM(subquery) name ...
- hive子查询
如果集合中含有空值,不能使用not in的语法指令:但是可以使用in
- HIVE:用外连接替代子查询
由于hive也支持sql,很多人会把hql跟标准sql进行比较,甚至有的时候会直接套用.hive不支持事务也不支持索引,更不支持追加写,但是对于一般的sql都是能够支持的.但是对于一些子查询确实无法支 ...
- hive中的子查询改join操作(转)
这些子查询在oracle和mysql等数据库中都能执行,但是在hive中却不支持,但是我们可以把这些查询语句改为join操作: -- 1.子查询 select * from A a where a.u ...
- Hive学习之Union和子查询
Union的语法格式如下: select_statement UNION ALL select_statement UNION ALL select_statement ... Union用于将多个S ...
- Hive进阶_Hive的子查询
- 集合中如果含null数据,不可使用not in, 可以使用in- hive只支持where和from子句中的子查询- 主查询和自查询可以不是同一张表 select e.ename from emp ...
- 关于Hive中case when不准使用子查询的解决方法
在公司用Hive实现个规则的时候,遇到了要查询某个字段是否在另一张表中,大概情况就是 A表: id value1 value2 1 100 0 2 101 1 3 102 1 B表: value1 1 ...
- hive 连接查询sql对比效率
准备4个表 从mysql 导出excel 转换为txt 创建hive 表的导入文件 create table bdqn_student( sno int, sname string, sbirthda ...
随机推荐
- [转]字符串相似度算法(编辑距离算法 Levenshtein Distance)
转自:http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=981 http://www.cnblogs.com/ivanyb/archi ...
- JQuery EasyUI 扩展方法 日期控件 设置时间段函数
/** Jquery扩展方法--by hgx 2018年1月8日-- * 设置时间段函数,开始时间(1号)与结束时间(当前日期) * 传入参数:--spaceMonth:查询间隔月,1为间隔查询一个月 ...
- org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.my.service.ProductService] for bean with name 'productService' defi报错解决方法
原 javaweb项目报错org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [XXX] ...
- maven 介绍(二)
本文内容主要摘自:http://www.konghao.org/index 内部视频 三.仓库 仓库:本地仓库:远程仓库:私有仓库(nexus) 1. nexus 的安装: 1). 下载并且解压缩 2 ...
- app安全研究
国内Android App在线漏洞检测平台 腾讯金刚审计系统 http://service.security.tencent.com/kingkong 免费 无限制 腾讯御安全 http://yaq ...
- debug教程
名称 解释 格式 a (Assemble) 逐行汇编 a [address] c (Compare) 比较两内存块 c range address d (Dump) 内存16进制显示 d [addre ...
- oppo R9 WLAN使用代理图解
以上拼图便是oppo R9 WLAN使用代理图解,代理设为 '手动' ,主机名便是我的电脑的ip地址,端口号是9973: + 9973端口号 (微信web开发者工具不可更改): + 8888 端口号 ...
- 探讨"点"语法的奥秘
点语法 一直以来,都不理解什么是点语法,都说是相当于链接或是路径.也许我浏览的信息量少吧,看过好几篇有关的博文,没什么记载,本篇只是初步见解分析. 在javascript里,属性和方法都使用“点”语法 ...
- 百度console输出
try{ if(window.console&&window.console.log) { console.log("一张网页,要经历怎样的过程,才能抵达用户面前?\n一位新 ...
- Implement JSON Web Tokens Authentication in ASP.NET Web API and Identity 2.1 Part 3 (by TAISEER)
http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-api-an ...