带 sum 的窗口函数返回过大的数字
我很困惑为什么一个简单的求和窗口函数返回以下输出,请注意“运行总计”值:
我的查询是:
select month,
"total sales",
sum("total sales") over (order by "month number" asc) as "running total"
from
(
select to_char(date, 'Month') as month,
sum(sale_price) as "total sales",
extract(MONTH from date) as "month number"
from sales
group by month, "month number"
) as sub_sales
order by "month number" asc;
我的输入数据如下:
我希望这样的结果是“运行总计”列返回 sale_price 的累积总和。
I'm confused about why a simple sum window function is returning the below output, note the "running total" value:
My query is:
select month,
"total sales",
sum("total sales") over (order by "month number" asc) as "running total"
from
(
select to_char(date, 'Month') as month,
sum(sale_price) as "total sales",
extract(MONTH from date) as "month number"
from sales
group by month, "month number"
) as sub_sales
order by "month number" asc;
My input data is the following:
I would expect this to work out such that the "running total" column returns a cumulative sum of sale_price.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这解决了这个问题,基于 @AdrianKlaver 评论:
但不确定为什么运行总计会以这种方式格式化?
This solved the issue, based on @AdrianKlaver comment:
Not sure why the running total would be formatted that way, though?