zoukankan      html  css  js  c++  java
  • 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 ' '
    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;



  • 相关阅读:
    xtrabackup详细用法
    CentOS国内YUM源及配置
    CentOS7系统配置国内yum源和epel源
    Zabbix的定期备份
    Zabbix的邮件告警
    石头剪刀布---组合数取模,数论
    组合数取模介绍----Lucas定理介绍
    乘法逆元
    费马小定理
    欧几里德与扩展欧几里德算法----数论
  • 原文地址:https://www.cnblogs.com/meiLinYa/p/9302991.html
Copyright © 2011-2022 走看看