Postgresql Window Function Count Distinct Subsequences