WINDOW FUNCTION SUM
description
计算窗口内数据的和
1. SUM([ALL] expression) [OVER (analytic_clause)]
example
按照 property 进行分组,在组内计算当前行以及前后各一行的x列的和。
1. select x, property,
2. sum(x) over
3. (
4. partition by property
5. order by x
6. rows between 1 preceding and 1 following
7. ) as 'moving total'
8. from int_t where property in ('odd','even');
10. | x | property | moving total |
11. |----|----------|--------------|
12. | 2 | even | 6 |
13. | 4 | even | 12 |
14. | 6 | even | 18 |
15. | 8 | even | 24 |
16. | 10 | even | 18 |
17. | 1 | odd | 4 |
18. | 3 | odd | 9 |
19. | 5 | odd | 15 |
20. | 7 | odd | 21 |
21. | 9 | odd | 16 |
keywords
1. WINDOW,FUNCTION,SUM
