oracle中求mtd,ytd
0
Hi 各位大神,我想在oracle中得到下列结果:
yearmonth, mtd, ytd
201601, 10, 10
201602 10, 20
201701 20, 20
201702 20, 40
......
求支招。
yearmonth, mtd, ytd
201601, 10, 10
201602 10, 20
201701 20, 20
201702 20, 40
......
求支招。
没有找到相关结果
重要提示:提问者不能发表回复,可以通过评论与回答者沟通,沟通后可以通过编辑功能完善问题描述,以便后续其他人能够更容易理解问题.
2 个回复
seng - 从事BI、大数据、数据分析工作 2017-08-03 回答
赞同来自:
SELECT a.yearmonth, substr(a.yearmonth,1,4),
mtd,
--注意ROWS BETWEEN unbounded preceding AND current row 是指第一行至当前行的汇总
SUM(mtd) OVER(PARTITION BY substr(a.yearmonth,1,4)
ORDER BY a.yearmonth
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as ytd
FROM a;
不过我比较喜欢对应表^-^
zhuseahui - 让痛苦痛苦 2017-08-03 回答
赞同来自: