]1、根据dept,emp,salgrade三张表结构,在Hive中创建类似的三张表。
例如
hive> create table dept(
> deptno int,
> dname char(14),
> loc char(13))
> row format delimited fields terminated by ',‘;
2、将dept,emp,salgrade三张表数据导入Hive对应的表中。
例如
load data local inpath ‘/home/Hadoop/student.txt’ overwrite into table student;
3、查询emp表所有员工所在部门情况
select distinct deptno from emp;
4、查询emp表相同部门不同职位的部门职位信息
select distinct deptno,job from emp;
5、将部门编号不为10的所有员工按员工编号升序排列
select * from emp where deptno <>10 order by empno asc;
6、将所有员工先按部门编号升序,当部门一样时,再按姓名降序排
select empno,ename, job, deptno from emp
> order by deptno asc,ename desc;
7、查看emp表中平均薪水是多少并对其四舍五入保留两位小数显示
select round(avg(sal),2) from emp;
8、统计emp表中有多少个不重复部门
select count(distinct deptno) from emp;
9、查询emp表平均薪水大于2000的部门编号、平均薪水
select avg(sal),deptno form from emp group by deptno having
avg(sal)>2000;
10、在emp表中,工资最高的员工姓名、薪水
select ename,sal from emp as a ,(select max(sal) as max_sal
from emp) as b where a.sal=b.max_sal;
11、在emp表中,工资高于平均工资员工姓名、薪水
select ename,sal from emp as a,(select avg(sal) avg_sal from
emp) as b where a.sal > b.avg_sal;
12、查询emp表平均年薪小于30000的部门编号、平均年薪
select 12*avg(sal),deptno from emp group by deptno having
avg(sal)*12<30000;