sql - 在 PostgreSQL 中选择不同的窗口函数
解决方案
一种方法使用数组:
select t.*,
(select count(distinct c) from unnest(ar) c) as num_distinct
from (select t.*,
array_agg(continuity) over (order by distance rows between 9 preceding and current row) ar
from t
) t;
编辑:
或者,如果您想要这些值,请将它们聚合:
select t.*,
(select array_agg(distinct c) from unnest(ar) c) as num_distinct
from (select t.*,
array_agg(continuity) over (order by distance rows between 9 preceding and current row) ar
from t
) t;
推荐阅读
- c# - 如何使用 .NET Core 配置 Elmah 以登录到 SQL?
- tensorflow - 如何为张量流模型推理输入多特征
- r - 如何_to_set_`list.len=1000`_global_in_R?
- scala - 如何更快地使用 select over avro struct 进行流式查询?
- visual-studio - 如何为 .NetCore 服务创建 exe
- php - 使用 CodeIgniter 3.1.10 发送电子邮件
- javascript - 如何使用 Map() 在 React 中创建 HTML 表格
- android - React Native 应用程序在 Google Play 商店上传 apk 后崩溃,它仅在第一次崩溃
- javascript - 根据另一个数组的值显示数组的值
- google-chrome - Chrome 浏览器在启动浏览器后未获取 URL。我将所有最新版本用于(浏览器、Selenium、驱动程序管理器、ChromeDriver)