标签:research operation 信息 over turn 平均工资 ada sea 转换
格式转换:cast(xxx as int)
按某列分桶某列排序,排序后打标机;例如:求每个地区工资最高的那个人的信息;
row_number() over(distribute by t1.loc sort by cast(t1.sal as int) desc) as index
hive> select * from dept; # deptno(部门编号) dname(部门名称) loc(部门所在地区) 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON
hive> select * from ump; # 员工编号 员工姓名 职务 领导编号 入职日期 工资 奖金 部门编号 # empno ename job mgr hiredate sal comm deptno 7369 SMITH CLERK 7902 1980-12-17 800.0 0.0 20 7499 ALLEN SALESMAN 7698 1981-02-20 1600.0 300.0 30 7521 WARD SALESMAN 7698 1981-02-22 1250.0 500.0 30 7566 JONES MANAGER 7839 1981-04-02 2975.0 0.0 20 7654 MARTIN SALESMAN 7698 1981-09-28 1250.0 1400.0 30 7698 BLAKE MANAGER 7839 1981-05-01 2850.0 0.0 30 7782 CLARK MANAGER 7839 1981-06-09 2450.0 0.0 10 7788 SCOTT ANALYST 7566 1987-07-13 3000.0 0.0 20 7839 KING PRESIDENT NULL 1981-11-07 5000.0 0.0 10 7844 TURNER SALESMAN 7698 1981-09-08 1500.0 0.0 30 7876 ADAMS CLERK 7788 1987-07-13 1100.0 0.0 20 7900 JAMES CLERK 7698 1981-12-03 950.0 0.0 30 7902 FORD ANALYST 7566 1981-12-03 3000.0 0.0 20 7934 MILLER CLERK 7782 1982-01-23 1300.0 0.0 10
select count(empno) from ump; #Total MapReduce CPU Time Spent: 5 seconds 170 msec #OK #14
select count(distinct job) from ump;
#Total MapReduce CPU Time Spent: 4 seconds 930 msec #OK #5
select job ,count (*)as emp_cnt from ump group by job order by emp_cnt desc; SALESMAN 4 CLERK 4 MANAGER 3 ANALYST 2 PRESIDENT 1
select ump.ename,ump.hiredate from ump join (select min(hiredate) as hiredate from ump)t1 where ump.hiredate=t1.hiredate; #SMITH 1980-12-17
select job ,max(sal)as max_sale,avg(sal)as min_sale from ump group by job;
ANALYST 3000.0 3000.0
CLERK 950.0 1037.5
MANAGER 2975.0 2758.3333333333335
PRESIDENT 5000.0 5000.0
SALESMAN 1600.0 1400.0
select t2.loc,t2.ename,t2.sal from (select t1.loc,t1.ename,t1.sal, row_number() over(distribute by t1.loc sort by cast(t1.sal as int) desc) as index from (select dept.loc,ump.ename,ump.sal from dept join ump on dept.deptno=ump.deptno)t1 )t2 where t2.index=1; #CHICAGO BLAKE 2850.0 #DALLAS FORD 3000.0 #NEW KING 5000.0
select t1.loc,count(*)as cnt from (select dept.loc,ump.ename, cast(substr(ump.hiredate,6,2) as int) as hire_month from dept join ump on dept.deptno=ump.deptno)t1 where t1.hire_month<=6 group by t1.loc order by cnt desc limit 1; CHICAGO 3
标签:research operation 信息 over turn 平均工资 ada sea 转换
原文地址:https://www.cnblogs.com/students/p/10162400.html