SELECT * FROM (
SELECT
    P.person_id,
    P.employee_code,
    P.first_name,
    P.last_name,
    P.email,
    P.primary_telephone,
    P.address1,
    P.address2,
    P.city,
    P.country,
    P.state_province_region,
    P.zip_or_postal_code,
    P.is_blocked,
    CD.data_json AS customdata,
    P_G.membership,
    rowNum as rowIndex
FROM
    (SELECT
        P.person_id, LISTAGG(g.group_code, ', ') WITHIN GROUP (ORDER BY g.group_code) membership
    FROM
        (SELECT
        P.person_id
    FROM
        person P
