Один метод использует массивы:
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:
Или, если вы хотите значения, агрегируйте их:
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;