小编Ant*_*al'的帖子

为什么 PostgreSQL WINDOW 函数会影响 select 中所有行的最终排序?

假设我们有以下查询。

\n
select\n    name,\n    pos,\n    rank() over (partition by constructor) r,\n    format('%s / %s',\n        row_number() over (partition by constructor),\n        count(*) over (partition by constructor)\n    ) "pos/global"\nfrom (values\n        ('d1-c1', 1, 'c1'),\n        ('d3-c1', 3, 'c1'),\n        ('d3-c2', 3, 'c2'),\n        ('d2-c1', 2, 'c1'),\n        ('d2-c2', 2, 'c2')\n    ) t(name, pos, constructor);\n
Run Code Online (Sandbox Code Playgroud)\n

输出如下:

\n
 name  \xe2\x94\x82 pos \xe2\x94\x82 r \xe2\x94\x82 pos/global\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xaa\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xaa\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xaa\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\n d1-c1 \xe2\x94\x82   1 \xe2\x94\x82 1 \xe2\x94\x82 1 / 3\n d3-c1 \xe2\x94\x82   3 \xe2\x94\x82 1 \xe2\x94\x82 2 / 3\n d2-c1 \xe2\x94\x82   2 \xe2\x94\x82 1 \xe2\x94\x82 …
Run Code Online (Sandbox Code Playgroud)

postgresql window-functions

1
推荐指数
1
解决办法
444
查看次数

标签 统计

postgresql ×1

window-functions ×1