The following query constructs a Department element that has an attribute "name" and child elements "emp" (a list of employees) ordered on the last names of the employees. One department element is created for each WORKDEPT.
SELECT XMLSERIALIZE(DOCUMENT XMLDOCUMENT (XMLELEMENT(NAME "Department", XMLATTRIBUTES(E.WORKDEPT AS "name"), XMLAGG(XMLELEMENT ( NAME "emp", E.LASTNAME) ORDER BY E.LASTNAME) )) AS CLOB(200)) AS "dept_list" FROM EMPLOYEE E WHERE E.WORKDEPT IN ('C01', 'E21') GROUP BY WORKDEPT;