答案 0 :(得分:1)
一种方法使用数组:
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;