1.创建表(根据文本内容)
1 create table mytable(id int,name string,gender string,age int) row format delimited fields terminated by ' '; 2 #验证操作 3 dfs -ls /uesr/hive/warehouse; 4 #创建表到指定位置 5 create table tb2(id int,name string) location '/user/hive/tb2 ;
2.topN查询
1 select * from mytable sort by age desc limit 3;
3.保存结果
a.将结果保存的创建的新表中
1 create table result as select avg(salary) from mytable;
b.将结果导出到指定路径下(文件夹)
1 insert overwrite local directory '/root/res' select avg(salary) from mytable;
c.将结果保存到集群上
1 insert overwrite directory '/sjw/out' select avg(salary) from mytable;
insert into 追加
insert overwrite 重写