Which statement will return a comma-separated list of employee names in alphabetical order for each department in the EMP table?
Which statement will return a comma-separated list of employee names in alphabetical order for each department in the EMP table?
The correct SQL statement should select the department number and create a comma-separated list of employee names in alphabetical order for each department. This can be achieved using the LISTAGG function with the appropriate ordering within each department group. Therefore, the correct statement is "SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employee_list FROM emp GROUP BY deptno;" which uses LISTAGG to concatenate employee names in alphabetical order within their respective departments.
A Correct select department_id, listagg(last_name, ',') within group (order by last_name) from employees group by department_id;
B, C, D will throw error. A is the only correct option
tried it in sql developer