QuestionQ1

VerifiedReporting Aggregated Data Using the Group Functions

Examine the structure of the EMPLOYEES table:

Question Image

You want to generate a report that contains the department IDs and last names of employees ordered by hire date in their respective departments. Employees from one department must appear in a single row.

Which query will provide the required output?

Explanation

LISTAGG(last_name, ';') WITHIN GROUP (ORDER BY hire_date) aggregates the last names of every employee sharing a department into one delimited string ordered internally by hire date, and GROUP BY department_id collapses each department onto a single output row; ordering the outer query by department_id then presents exactly one row per department as required. The other candidate statements either try to order the aggregated result by hire_date, a column that is neither grouped nor aggregated and therefore cannot be used in the outer ORDER BY, or contain a stray or missing parenthesis around the LISTAGG...WITHIN GROUP clause that makes the statement fail to parse.

Community Discussion

No comments yet. Be the first to start the discussion!