欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Greenplum 中的窗口函数详解

最编程 2024-07-23 08:01:22
...
tutorial=> select id, name , sum(id) over () sum1,
tutorial-> sum(id) over (order by id) sum2,
tutorial-> sum(id) over ( partition by name) sum3,
tutorial-> sum(id) over ( partition by name order by name desc) sum4
tutorial-> from test002;
id | name | sum1 | sum2 | sum3 | sum4
----+------+------+------+------+------
  1 | gh2  |   16 |    2 |    9 |    9
  1 | gh   |   16 |    2 |    1 |    1
  2 | gh2  |   16 |    6 |    9 |    9
  2 | gh2  |   16 |    6 |    9 |    9
  3 | gh4  |   16 |   12 |    3 |    3
  3 | gh3  |   16 |   12 |    3 |    3
  4 | gh2  |   16 |   16 |    9 |    9
(7 rows)