Monday, April 4, 2022

DB - LISTAGG() function | Aggregate fuction

Sometimes we need to aggregate data from a number of rows into a single row and associate the result row with a specific value.

For example, following query returns a comma separated list of employees for each job title.

Table:
Employees:
Employee_Id
First_name
Last_name
Email
Phone
Hire_date
Manager_id
Job_title

Query:

Select 
Job_title,
LISTAGG(
First_name, ',',) within group( order by first_name) as employees
From employees
Group by job_title
Order by
Job_title;






No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...