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;



  • 相关阅读:
    MyBatis 配置文件 用户密码加密存储
    MyBatis 实例
    mybatis 入门搭建
    文件上传
    struts 结果类型
    Struts 拦截器
    log4j
    Struts Action 控制器
    Struts
    四、常用的Maven命令
  • 原文地址:https://www.cnblogs.com/meiLinYa/p/9302991.html
Copyright © 2011-2022 走看看