Postgresql Window Function Count In R