mysql分析函数语法问题求教
selectadb_time,week_name,sum(busi_table_sub_discount_num)over()
,sum(busi_table_sub_discount_num)
from ads_busi_daily_report_di_v3
where adb_time <= 20210415 and adb_time >= 20210412
group by adb_time,week_name。结果报错:`qbi`.`sum`(`busi_table_sub_discount_num`) OVER ()' must be an aggregate expression or appear in GROUP BY clause
就是说该分析函数的字段也必须是聚合函数或者groupby里的,但是,问题来了,sum()难道不是聚合吗?
最后我是通过在套一层sum解决的,但是这个问题想不通,求各位大佬指正。。而且我记得我以前这么写过啊。。。。oracle可以这么用吗
分组求和函数你可能理解的有点问题。。sum(a)over()你在里面不写partition by 子句的情况下,它执行逻辑是对所有字段分组对a求和。相当于select sum(a) from table group by 所有的字段;
你想要分组求和可以这样,sum()over(partition by adb_time,week_name)。
页:
[1]