How can I get the result specified below?
I tried using the LISTAGG function, but it does not eliminate duplicates.
Is there a way to eliminate duplicates at the database itself instead of fetching the values into the service and then deduping them?
Dataset:
col0 col1
1 7
1 8
1 8
1 2
1 9
2 9
3 10
3 11
3 12
Desired result:
col0 col1
1 2,7,8,9
2 9
3 10,11,12
Attempted SQL (that does not eliminate duplicates):
SELECT
col0,
SUM(col2 + col3) AS mycount
LISTAGG(col1, ',') within GROUP (ORDER BY col1)
FROM mytable
WHERE
_time >= TIMESTAMP '2024-12-03 00:00:00' AND
_time < TIMESTAMP '2024-12-03 01:00:00'
GROUP BY col0
ORDER BY mycount DESC
LIMIT 10
;

DISTINCTkeyword to theLISTAGGfunction