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=1will have3distinct valuesid=2will have2distinct values asbb//43as shown up twice, thus 2 distinct valuesid=3will have0distinct values as it as an empty listid=4will have1since 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 |