We all are aware of concatenating multiple column data into one column but when it comes to concatenating multiple rows into one column we always start looking for an answer on the net.
Here I have the solution for both :-
Concatenate Columns into one column:-
SELECT organization_id,
BUSINESS_GROUP_ID,
CONCAT (organization_id, BUSINESS_GROUP_ID)
FROM hr_All_organization_units
WHERE organization_id IN (81, 82, 83);
Concat Rows into one Column:-
SELECT LISTAGG (organization_id, ';') WITHIN GROUP (ORDER BY organization_id)
organization_id,
LISTAGG (BUSINESS_GROUP_ID, ';')
WITHIN GROUP (ORDER BY BUSINESS_GROUP_ID)
BUSINESS_GROUP_ID
FROM hr_All_organization_units
WHERE organization_id IN (81, 82, 83);
Here I have the solution for both :-
Concatenate Columns into one column:-
SELECT organization_id,
BUSINESS_GROUP_ID,
CONCAT (organization_id, BUSINESS_GROUP_ID)
FROM hr_All_organization_units
WHERE organization_id IN (81, 82, 83);
Concat Rows into one Column:-
SELECT LISTAGG (organization_id, ';') WITHIN GROUP (ORDER BY organization_id)
organization_id,
LISTAGG (BUSINESS_GROUP_ID, ';')
WITHIN GROUP (ORDER BY BUSINESS_GROUP_ID)
BUSINESS_GROUP_ID
FROM hr_All_organization_units
WHERE organization_id IN (81, 82, 83);
No comments:
Post a Comment