I have this table called test
id | my_list |
---|---|
1 | aa//11, aa//34, ab//65 |
2 | bb//43, bb//43, be//54 |
3 | |
4 | cc//76 |
I want to count the distinct values in my_list
, where each item in the list is separated by a comma. In this case:
id=1
will have3
distinct valuesid=2
will have2
distinct values asbb//43
as shown up twice, thus 2 distinct valuesid=3
will have0
distinct values as it as an empty listid=4
will have1
since there is only 1 item in the list
I want to do this in pure SQL and not using a custom made procedure. I tried with the statement below but it is showing 1.
SELECT id, COUNT(DISTINCT my_list) as my_count
FROM test;
Expected result:
id | my_count |
---|---|
1 | 3 |
2 | 2 |
3 | 0 |
4 | 1 |