Good morning Anna,
I can't speak to the row number issue as I've never had occasion to work with it.
But regarding the LISTAGG issue, here are a few suggestions. I usually have to tweak the syntax to get exactly what I want in each query. But these are my starting points. I also recommend the website:
https://www.techonthenet.com/oracle/functions/regexp_replace.php
It includes several excellent tables of syntax operators and examples of their use.
Tristan Bender's Non-repeating LISTAGG:
RTRIM(REGEXP_REPLACE((LISTAGG(D.BUSINESS_UNIT, ', ') WITHIN GROUP (ORDER BY D.BUSINESS_UNIT) ), '([^, ]*)(, \1)+($|, )', '\1, '), ', ')
Scott Frey's:
(REGEXP_REPLACE (LISTAGG (J.DEPTID, ', ') WITHIN GROUP (ORDER BY J.DEPTID),
'(\W[^,]+)(,[ ]*\1)+',
'\1'))
Alternate Scott Frey's:
(REGEXP_REPLACE (LISTAGG (J.DEPTID, ', ') WITHIN GROUP (ORDER BY J.DEPTID),
'([^,]+)(,[ ]*\1)+',
'\1'))
------------------------------
Scott Frey
Senior Data Analyst - Human Resource Information Systems
University of Colorado System
------------------------------
Message from the HEUG Marketplace:------------------------------
Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the
HEUG Marketplace.
------------------------------