zoukankan      html  css  js  c++  java
  • hive 运行sql报错Expression Not In Group By Key

    案例:

    Select tmp.username,date,sum(tmp.su) over(partition by tmp.username order by tmp.date ) totle
        From  (
            Select username,sum(cost_money) su,date
            From table_test1
            Group by date,username
                ) tmp
        Group by tmp.date,tmp.username
        Order by tmp.username;

    mysql运行结果:

    hive提示:Semantic Exception: Line 1:24 Expression not in GROUP BY key 'su' (state=42000,code=40000)

    原因:1.Hive不允许直接访问非group by字段;

    解决:
    1.对于非group by字段,可以用Hive的collect_set函数收集这些字段,返回一个数组;
    2.使用数字下标,可以直接访问数组中的元素;

    也可以直接将字段放入group by中:

    Select tmp.username,date,sum(tmp.su) over(partition by tmp.username order by tmp.date ) totle
        From  (
            Select username,sum(cost_money) su,date
            From table_test1
            Group by date,username
                ) tmp
        Group by tmp.date,tmp.username,su
        Order by tmp.username;
  • 相关阅读:
    HttpServletResponse对象
    FastJSON 简介及其Map/JSON/String 互转(转载)
    commons-lang3-3.4类库
    HttpClient相关
    JSON.parse()方法 (转载)
    textview用法--推荐
    每日总结
    百度网盘
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/zhipeng-wang/p/14537912.html
Copyright © 2011-2022 走看看