WINDOW FUNCTION COUNT

description

计算窗口内数据出现次数

  1. COUNT(expression) [OVER (analytic_clause)]

example

计算从当前行到第一行x出现的次数。

  1. select x, property,
  2. count(x) over
  3. (
  4. partition by property
  5. order by x
  6. rows between unbounded preceding and current row
  7. ) as 'cumulative total'
  8. from int_t where property in ('odd','even');
  9. | x | property | cumulative count |
  10. |----|----------|------------------|
  11. | 2 | even | 1 |
  12. | 4 | even | 2 |
  13. | 6 | even | 3 |
  14. | 8 | even | 4 |
  15. | 10 | even | 5 |
  16. | 1 | odd | 1 |
  17. | 3 | odd | 2 |
  18. | 5 | odd | 3 |
  19. | 7 | odd | 4 |
  20. | 9 | odd | 5 |

keywords

  1. WINDOW,FUNCTION,COUNT