设为首页 加入收藏

TOP

Hive - - 分组求最大,最小(加行键)
2018-12-07 01:20:08 】 浏览:89
Tags:Hive --分组 最大 最小 加行键
版权声明:请注明出处:https://www.cnblogs.com/meiLinYa/ https://blog.csdn.net/meiLin_Ya/article/details/80978658

Hive - - 分组求最大,最小(加行键)

数据:


1325927 陕西 汉中 084 0849
1325928 陕西 汉中 084 0849
1325930 陕西 延安 084 0842
1325931 陕西 延安 084 0842
1325933 陕西 榆林 084 0845
1325935 陕西 榆林 084 0845
1325941 陕西 西安 084 0841
1325943 陕西 西安 084 0841
1325944 陕西 西安 084 0841
1325946 陕西 西安 084 0841
1325947 陕西 西安 084 0841
1325948 陕西 西安 084 0841
1325949 陕西 西安 084 0841

建表,添加数据

create table if not exists tab4(

no string,
province string,
city string,
pid string,
cid string
)
row format delimited fields terminated by '\t'
stored as textfile;


load data local inpath '/home/data/data4.txt' into table tab4;




求最大
select t.*
from(
select no,province,city,pid,cid,row_number() over(partition by province,city order by pid desc) rk
from tab4) t
where t.rk=1;


求最小:

select t.*
from(
select no,province,city,pid,cid,row_number() over(partition by province,city order by pid) rk
from tab4) t
where t.rk=1;


查询所有省份,并且分组给city标识列进行排序

select *,row_number() over(partition by province,city order by city) rk
from tab4;



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇如何用shell调用hive 下一篇大数据平台入门--hive安装(虚拟..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目