One method uses arrays:
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;
EDIT:
Or, if you want the values, aggregate them:
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.