立即学习: https://edu.csdn.net/course/play/8005/164134?utm_source=blogtoedu
create table test3 as select id,name from test2 where province='hebei' and city='baoding';
--导出hive数据到本地目录(下载)
insert overwrite local directory '/home/hadoop/hive'
select * from hive1.test1
where province='hebei';
--导出hive数据到hdfs目录
insert overwrite directory '/user/hadoop/data'
select * from hive1.test1
where province='hebei';
--查询数据向多个目录同时输送
from hive1.test2 t
insert overwrite directory '/home/hadoop/hive/hebei'
select * where t.province='hebei'
insert overwrite directory '/home/hadoop/hive/henan'
select * where t.province='henan';
select col1,col2 from table t;
select upper(name) from test2; // name大写
select lower(name) from test2; // name小写
select age + 10 from test2;
select round(12.34); //12 四舍五入
select floor(12.34); //12 地板
select ceil(12.34); //13 天花板
select rand(10); //随机数
select count(*) from test2;
select sum(age) from test2;
select avg(age) from test2;
select max(age) from test2;
select min(age) from test2;
select count(distinct name) from test2;
select ascii("abc");
select ascii('abc');
select base64(binary('http://localhost:8080/helloworld'));
select binary('http://localhost:8080/helloworld');
select cast('120' as bigint) + 200; //320
select '120' + 200; //320.0
select concat('ab','cd'); //abcd
select * from test2 limit 1,2; //从第二条开始,查出来两条
from test2 e
select e.id,e.name,e.age
where e.city='baoding';
select e.id,e.name,e.age
from test2 e
where e.city='baoding';
select name,age, case
when age<20 then 'low'
when age>50 then 'old'
else 'big' end
as agestatus
from hive1.test2;
注意!!! hive 中的 where 语句不能使用别名
--select id, name n ,age from test2 where n like 't%'; //wrong where中不能使用字段别名
select * from test2 where age between 12 and 24;
select * from test2 where age <=24 and age >12;
select count(*),province
from test2
group by province;
select count(*) as c, province
from test2
group by province
having c>3;
不使用mr作业的模式就是本地作业,下面方法可以尽量避免mr作业。
select * from test;
select * from test2 where province='hebei';
set hive.exec.mode.local.auto=true;