尚硅谷大數(shù)據(jù)技術(shù)之Hive(新)第6章 查詢
5.2 數(shù)據(jù)導(dǎo)出
5.2.1 Insert導(dǎo)出
1.將查詢的結(jié)果導(dǎo)出到本地
hive (default)> insert overwrite local directory '/opt/module/datas/export/student'
????????????select * from student;
2.將查詢的結(jié)果格式化導(dǎo)出到本地
hive(default)>insert overwrite local directory '/opt/module/datas/export/student1'
???????????ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ????????????select * from student;
3.將查詢的結(jié)果導(dǎo)出到HDFS上(沒有l(wèi)ocal)
hive (default)> insert overwrite directory '/user/atguigu/student2'
?????????????ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
?????????????select * from student;
5.2.2 Hadoop命令導(dǎo)出到本地
hive (default)> dfs -get /user/hive/warehouse/student/month=201709/000000_0
/opt/module/datas/export/student3.txt;
5.2.3 Hive Shell 命令導(dǎo)出
基本語法:(hive -f/-e 執(zhí)行語句或者腳本 > file)
[atguigu@hadoop102 hive]$ bin/hive -e 'select * from default.student;' >
?/opt/module/datas/export/student4.txt;
5.2.4 Export導(dǎo)出到HDFS上
(defahiveult)>?export table default.student to
?'/user/hive/warehouse/export/student';
5.2.5 Sqoop導(dǎo)出
后續(xù)課程專門講。
5.3 清除表中數(shù)據(jù)(Truncate)
注意:Truncate只能刪除管理表,不能刪除外部表中數(shù)據(jù)
hive (default)> truncate table student;
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select
查詢語句語法:
[WITH CommonTableExpression (, CommonTableExpression)*]??? (Note: Only available ?starting with Hive?0.13.0) SELECT [ALL | DISTINCT] select_expr, select_expr, ... ??FROM table_reference ??[WHERE where_condition] ??[GROUP BY col_list] ??[ORDER BY col_list] ??[CLUSTER BY col_list ????| [DISTRIBUTE BY col_list] [SORT BY col_list] ??] ?[LIMIT number] |
6.1 基本查詢(Select…From)
6.1.1 全表和特定列查詢
1.全表查詢
hive (default)> select * from emp;
2.選擇特定列查詢
hive (default)> select empno, ename from emp;
注意:
(1)SQL 語言大小寫不敏感。?
(2)SQL 可以寫在一行或者多行
(3)關(guān)鍵字不能被縮寫也不能分行
(4)各子句一般要分行寫。
(5)使用縮進(jìn)提高語句的可讀性。