oracle sql listagg 1

oracle sql listagg

SELECT
    job_title,
    LISTAGG(
        first_name,
        ','
    ) WITHIN GROUP(
    ORDER BY
        first_name
    ) AS employees
FROM
    employees
GROUP BY
    job_title
ORDER BY
    job_title;

Here is what the above code is Doing:
1. We’re selecting the job_title and employees columns.
2. We’re using the LISTAGG function to aggregate the first_name column.
3. We’re using the WITHIN GROUP clause to order the first_name column alphabetically.
4. We’re grouping the job_title column.
5. We’re ordering the job_title column alphabetically.

Similar Posts