hive之HQL 排序

hive之HQL 排序
查询员工信息:员工号 姓名 月薪 按月薪排序
select empno,ename,sal from emp order by sal; 若在尾部加上desc,按降序排列
排序操作要被转换成mapreduce作业,order by 后面可跟:列、表达式、别名或序号。
select empno,ename,sal,sal*12 from emp order by sal*12; 按年薪进行排序
select empno,ename,sal,sal*12 from emp order by 4;年薪为第4列,所以此次排序也是按年薪排序
hive>set hive.groupby.orderby.position.alias=true;
该值缺省状态是false,是不能使用查询语句的序号,若想使用序号,就必须将该值设置为true
下面我们查询员工信息,按照奖金排序,但是在comm这一列是有空值的情况的,升序时排前,降序时排后,最好将null转换成0
select empno,ename,sal,comm from emp order by comm;

猜你喜欢

转载自blog.csdn.net/lepton126/article/details/80326126
今日推荐