union不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause
union all
union
相同点 是 相当于上下拼接 上下两个拼接表必须字段保持一致
不同 union有去重效果,速度会更慢。
=============================================================================================================================
union all的子句里不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause
解决:改造hql,去掉union all子查询里的orderByClause、clusterByClause、distributeByClause、sortByClause和limitClause语句
示例:select t.id from (select dummy from default.dual limit 1 union all select dummy from default.dual limit 1)t;
去掉两个子查询里的limit 1;
create table lk3 (id string,nname string,grade int,goldUser int); insert into lk3 values
(1,'jack',300, 10 ),
(2,'mach', 200, 10 ),
(3,'lich', 100 ,10 ),
(4,'rock', 1, 0 ),
(5,'mick', 1 ,10 ),
(6,'kight', 0 ,10 ),
(7,'babaya', 0, 0 ),
(8,'kano', 0, 10);
select * from lk3;
+---------+------------+------------+---------------+--+
| lk3.id | lk3.nname | lk3.grade | lk3.golduser |
+---------+------------+------------+---------------+--+
| 1 | jack | 300 | 10 |
| 2 | mach | 200 | 10 |
| 3 | lich | 100 | 10 |
| 4 | rock | 1 | 0 |
| 5 | mick | 1 | 10 |
| 6 | kight | 0 | 10 |
| 7 | babaya | 0 | 0 |
| 8 | kano | 0 | 10 |
+---------+------------+------------+---------------+--+
报错代码:
0: jdbc:hive2://localhost:10000> SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser;
Error: Error while compiling statement: FAILED: ParseException line 3:63 Failed to recognize predicate '<EOF>'.
Failed rule: 'orderByClause clusterByClause distributeByClause sortByClause limitClause can only be applied to the whole union.' in statement (state=42000,code=40000)
正确处理
0: jdbc:hive2://localhost:10000> select * from (SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser limit 1) a
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser limit 2,3;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
+--------+-----------+-----------+--------------+--+
| u1.id | u1.nname | u1.grade | u1.golduser |
+--------+-----------+-----------+--------------+--+
| 2 | mach | 200 | 10 |
| 3 | lich | 100 | 10 |
| 7 | babaya | 0 | 0 |
+--------+-----------+-----------+--------------+--+
3 rows selected (33.439 seconds)
还有上下字段必须一致的验证:
0: jdbc:hive2://localhost:10000> select id,nname from (SELECT * FROM lk3 where grade != 1 order by grade desc,goldUser limit 1) a
. . . . . . . . . . . . . . . .> union all
. . . . . . . . . . . . . . . .> select * from lk3 where grade != 1 order by grade desc,goldUser limit 2,3;
Error: Error while compiling statement: FAILED: SemanticException Schema of both sides of union should match. (state=42000,code=40000)
union不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause的更多相关文章
- 【HIVE】sql语句转换成mapreduce
1.hive是什么? 2.MapReduce框架实现SQL基本操作的原理是什么? 3.Hive怎样实现SQL的词法和语法解析? 连接:http://www.aboutyun.com/thread-20 ...
- Hive SQL 编译过程
转自:http://www.open-open.com/lib/view/open1400644430159.html Hive跟Impala貌似都是公司或者研究所常用的系统,前者更稳定点,实现方式是 ...
- [Hive]HiveSQL解析原理
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- 【转】Hive SQL的编译过程
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- Hive SQL的编译过程
文章转自:http://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是 ...
- 转:Hive SQL的编译过程
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- Hive SQL的编译过程[转载自https://tech.meituan.com/hive-sql-to-mapreduce.html]
https://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hi ...
- Hive SQL编译过程(转)
转自:https://www.cnblogs.com/zhzhang/p/5691997.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive ...
- SQL Server-聚焦UNIOL ALL/UNION查询(二十三)
前言 本节我们来看看有关查询中UNION和UNION ALL的问题,简短的内容,深入的理解,Always to review the basics. 初探UNION和UNION ALL 首先我们过一遍 ...
随机推荐
- [转帖]瀚高数据库创建uuid的方法
使用syssso登录,并执行下列语句 highgo=> select set_secure_level('off'); set_secure_level -------------------- ...
- PAT B1002 写出这个数(20)
AC代码 #include <cstdio> #include <iostream> #include <cstring> using namespace std; ...
- Spring MVC(一)Spring MVC的原理
1.Spring MVC的目的 构建像Spring框架那样灵活和松耦合的Web应用程序. 2.Spring MVC中如何处理Request? 每当用户在Web浏览器中点击链接或者提交表单时,Reque ...
- 在Window Server 2016中使用Web Deploy方式发布.NET Web应用
1.在IIS里面点击获取新的Web平台组件 2.下载Web平台组件并安装 3.在其中搜索Web Deploy,找到3.5版本,并安装 4.继续搜索Web Deploy 3.6版本,并安装 安装好之后, ...
- C#面向对象19 值传递和引用传递
值类型:int double char decimal bool enum struct引用类型:string 数组 自定义类 集合 object 接口 **值传递和引用传递1.值类型在复制的时候,传 ...
- unity 打包Error:WebException: The remote server returned an error: (403) Forbidden.
記一下在ios上打包出錯: UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors at UnityEditor.BuildPlaye ...
- 搭建自己的框架WedeNet(五)
WedeNet2018.WedeWcfServices-WCF服务层:结构如下: 就是定义了服务契约接口和服务类,以OrderServices为例,如下: using System; using Sy ...
- JS基础_if注意问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- MFC之CImageList(1)
CImageList BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow ); 其中各项参数的含义为:cx定义图像的宽度 ...
- css3常用样式
.box{ //改变轴的方向 flex-direction:column; //两端对齐 justify-content:space-between; //换行 flex-wrap: wrap; // ...