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

OIC - Moving a File using FTP connection now throws IO operation failed error

Error usecase: Moving a File using FTP connection now throws IO operation failed error. The integration has been working for weeks, with a f...