• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Loneliness Ends HUHU
热情坦诚
博客园    首页    新随笔    联系   管理    订阅  订阅
Hive - - 分组求最大,最小(加行键)

                            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;



posted on 2018-07-09 22:51  meiLinYa  阅读(457)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3