hive的資料查詢

2021-08-21 13:35:38 字數 1367 閱讀 1308

-------------hive的資料查詢-------------

-----------------查詢語法---------------

select [all|distinct] select_expr,select_expr,....

from table_reference

[where where_condition]

[group by col_list]

[cluster by col_list] | [distribute by col_list] | [sort by col_list] | [order by col_list]

[group by col_list]

[limit number]

-----------------簡單查詢-------------

--查詢所有員工的所有資訊

select * from emp;

--查詢員工資訊:員工號、姓名、月薪

select empno,ename,sal from emp;

--查詢員工資訊:員工號、姓名、月薪、年薪

select empno,ename,sal,sal * 12 from emp;

--查詢員工資訊:員工號、姓名、月薪,年薪(命名)

select empno,ename,sal,sal * 12 as year_sal from emp;

--查詢員工資訊:員工號、姓名、月薪、年薪、獎金 年收入

select empno,ename,sal,sal * 12 ,comm,sal * 12 + comm from emp;   --出現問題,獎金為null

select empno,ename,sal,sal * 12 ,comm,sal * 12 + nvl(comm,0) from emp;   --獎金為null的為0

--查詢獎金為null的員工

select * from emp where comm is null

--使用distinct去掉重覆記錄

select distinct deptno,job from emp 

-------簡單查詢的fetch task功能-----

--當select查詢時會使用mapreduce,但出現簡單查詢,可以使用fetch task功能,下面有三種方式設定

--配置方式:1、set hive.fetch.task.conversion=more

2、hive --hiveconf hive.fetch.task.conversion=more      

3、修改hive-site.xml檔案

hive.fetch.task.conversion

more

Hive的資料查詢

與mysql和oracle中的sql語句不一樣地方會特別標註 hive簡單查詢 宣告如下 select all distinct select expr,select expr,from table reference where where conditon group by col list c...

Hive之資料查詢

發布於 2013 年 10 月 11 日 由 aaron 發布於 hive 一,排序和聚合 對於排序有兩種方式,一種是order by 一種是sort by order by 會對所有的資料進行排序,所以最後會只有乙個reducer來處理,如果資料量非常大,效率會非常差勁 sort by是部分排序,...

Hive 05 資料查詢

select from table name select sid,sname from table name select sid sname sal sal 12from table name select sid sname sal comm,sal 12 nvl comm,0 from ta...