HiveSelect操作
儲存select查詢結果的幾種方式
1.將查詢結果儲存到一張新的hive表中create table t_tmp
as
select * from t_p;2將查詢結果儲存到一張已經存在的hive表中
eg:(into 增量增加)
insert into table t_tmp
select * from t_p;
#-----------------------------------------------------
eg:(overwrite 覆蓋增加)
insert overwrite table ol_oitf_interface_auc_dimension_value_business
select *
from tmp_auc_dimension_value_business_new;
3.將查詢結果儲存到指定的檔案目錄(可以是本地,也可以是HDFS)
insert overwrite local directory '/home/hadoop/test'
select * from t_p;
#---------------------------------------------------
#插入HDFS
insert overwrite directory '/aaa/test'
select * from t_p;
Group By操作
GROUP BY子句的語法如下:
SELECT [ALL | DISTINCT] select_expr, select_expr, … FROM
table_reference [WHERE where_condition] [GROUP BY col_list] [HAVING
having_condition] [ORDER BY col_list]] [LIMIT number];eg: SELECT
pageid, age, count(1) FROM pv_users GROUP BY pageid, age;
具體實現過程如圖:
例項:
presto:default> select *from(
-> select one_department,
-> two_department,
-> three_department,
-> four_department,
-> five_department ,count(*) as num from tmp_kn1_ehr_person_organization_20180817 where one_department is not Null group by one_department,
-> two_department,
-> three_department,
-> four_department,
-> five_department ) t2 where t2.num>1 limit 5;
Group By sum 計算
表資料:
presto:default> select *from tab4 order by id1;
id1 | size | name
------+------+------
1 | 10 | AAA
2 | 20 | BBB
3 | 30 | DDD
3 | 30 | CCC
4 | 40 | NULL
8 | NULL | HHH
99 | NULL | TTT
NULL | NULL | EEE
NULL | 76 | HHH
(9 rows)
計算 size 的總數
Group By 排列組合
表語句 (查詢tab4):
presto:default> select id1,size,name from tab4 group by id1,size,name order by id1;
id1 | size | name
------+------+------
1 | 10 | AAA
2 | 20 | BBB
3 | 30 | DDD
3 | 30 | CCC
4 | 40 | NULL
8 | NULL | HHH
99 | NULL | TTT
NULL | NULL | EEE
NULL | 76 | HHH
(9 rows)
tab4 分組:
presto:default> select id1,size from tab4 group by id1,size order by id1;
id1 | size
------+------
1 | 10
2 | 20
3 | 30
4 | 40
8 | NULL
99 | NULL
NULL | NULL
NULL | 76
(8 rows)
tab4 分組並 size列 賦值Null:
presto:default> select id1,'null' as size from tab4 group by id1,size order by id1;
id1 | size
------+------
1 | null
2 | null
3 | null
4 | null
8 | null
99 | null
NULL | null
NULL | null
(8 rows)
tab4 分組並 多出來一列 name 賦值Null:
presto:default>
presto:default> select id1,size,null as name from tab4 group by id1,size order by id1;
id1 | size | name
------+------+------
1 | 10 | NULL
2 | 20 | NULL
3 | 30 | NULL
4 | 40 | NULL
8 | NULL | NULL
99 | NULL | NULL
NULL | NULL | NULL
NULL | 76 | NULL
(8 rows)
tab4 分組並 多出來一列 size 賦值Null:
presto:default> select id1,size,null as size from tab4 group by id1,size order by id1;
id1 | size | size
------+------+------
1 | 10 | NULL
2 | 20 | NULL
3 | 30 | NULL
4 | 40 | NULL
8 | NULL | NULL
99 | NULL | NULL
NULL | NULL | NULL
NULL | 76 | NULL
(8 rows)
tab4 分組並少一列 size :
presto:default> select id1 from tab4 group by id1,size order by id1;
id1
------
1
2
3
4
8
99
NULL
NULL
(8 rows)
型別轉化 decimal()
create table tab5 as select res_pay_total,price_total,order_id,hotel_id,start_date from tmp_ol_dtfet_selftour_resales_date_go limit 10 union all 1.0000000000000000000000009 as res_pay_total, 2.00000000000009 as price_total,3 as order_id,5 as hotel_id,566 as start_date from dual;
Having
相關文章
- JQ操作標籤--樣式操作、 位置操作、尺寸、 文字操作、 獲取值操作、 屬性操作、文件處理、事件事件
- Pytorch AdaptivePooing操作轉Pooling操作PyTorchAPT
- Go 操作 Redis 的基本操作GoRedis
- 操作
- Hive高階操作-查詢操作Hive
- 坐下坐下,基本操作(ZooKeeper 操作篇)
- JavaScript騷操作之操作符JavaScript
- 使用java操作ranger,hdfs ranger授權操作,hive ranger授權操作JavaRangerHive
- 熟悉常用的Linux操作和Hadoop操作LinuxHadoop
- Go 語言操作 MySQL 之 CURD 操作GoMySql
- ES入門三部曲:索引操作,對映操作,文件操作索引
- 字串操作字串
- CAS操作
- 流操作
- 位操作
- git操作Git
- vim操作
- tlmgr 操作
- Anaconda 操作
- playwright 操作
- 日常操作
- firewalld操作
- gorm 操作GoORM
- DGfailover操作AI
- Git 操作Git
- docker操作Docker
- BOM操作
- Jedis操作
- conda操作
- js操作JS
- kibana 操作
- mongoDB操作MongoDB
- DOM操作
- checkbox操作
- DOM 操作
- flowable的查詢操作和刪除操作
- Go 語言操作 MySQL 之 事務操作GoMySql
- Linux 日常操作命令集合 -1程式操作Linux