Oracle SQL: sum( case when then amount else 0 END) OVER (partition by...) = 无法得到正确的 GROUP BY 语句
我正在尝试选择几个不同的总和,其中之一是OVER(按column_also_in_select_plan 分区)
。
但是,我似乎永远无法正确使用 GROUP BY
语句。
示例:
Select 1, 2, 3, sum(4) over (partition by 3), sum(case when 6 = etc...)
FROM table
Where filters
GROUP BY ?
感谢您的任何提示:)
I'm trying to select several different sums, one of them being OVER (Partition by column_also_in_select_plan)
.
However I cannot seem to ever be able to get the GROUP BY
statement right.
Example:
Select 1, 2, 3, sum(4) over (partition by 3), sum(case when 6 = etc...)
FROM table
Where filters
GROUP BY ?
Thanks for any tips :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同时使用窗口函数进行聚合并没有多大意义,所以你感到困惑我并不感到惊讶。在上面的示例中,您可能希望将窗口移动到外部查询,即:
It doesn't really make much sense to be doing aggregation and using window functions at the same time, so I'm not surprised you're confused. In the above example, you probably want to move the windowing to an outer query, that is: