Postgresql Count Distinct In Pivot Table