postgres: How to count distinct elements in array columns given a condition postgres: How to count distinct elements in array columns given a condition arrays arrays

postgres: How to count distinct elements in array columns given a condition


select id, count(distinct a1) as a1, count(distinct a2) as a2from (    select id, unnest(array1) as a1, unnest(array2) as a2    from t) sgroup by id