網上相關教程很多,這里我主要是簡單總結下幾種常用的方法,方便日后查詢。
第一種,在bash中直接通過hive -e命令,並用 > 輸出流把執行結果輸出到制定文件
hive -e "select * from student where sex = '男'" > /tmp/output.txt
第二種,在bash中直接通過hive -f命令,執行文件中一條或者多條sql語句。並用 > 輸出流把執行結果輸出到制定文件
hive -f exer.sql > /tmp/output.txt 文件內容 select * from student where sex = '男'; select count(*) from student;
第三種,在hive中輸入hive-sql語句,通過使用INSERT OVERWRITE LOCAL DIRECTORY結果到本地系統和HDFS文件系統
語法一致,只是路徑不同
insert overwrite local directory "/tmp/out" > select cno,avg(grade) from sc group by(cno);
insert overwrite directory 'hdfs://server71:9000/user/hive/warehouse/mystudent' select * from student1;
以上是三種,包含了3執行hive-sql的方法。結果保存到本地的方法前兩種都屬於linxu BASH自帶的方法。第三種才是HIVE本身的導出數據的方法。
第四種,就是基本的SQL語法,從一個表格中抽取數據,直接插入另外一個表格。參考SQL語法即可。
insert overwrite table student3 select sno,sname,sex,sage,sdept from student3 where year='1996';
http://blog.csdn.net/zhuce1986/article/details/39586189