In the Oracle SQL query, how can I pivot without hardcoding the values of leave_reason?
CREATE TABLE Persons (
group_id int,
leave_reason varchar(40),
person_id int,
number_of_days int
);
INSERT INTO Persons (group_id, leave_reason, person_id, number_of_days)
VALUES (1, 'Employee''s PTO', 44, 1);
INSERT INTO Persons (group_id, leave_reason, person_id, number_of_days)
VALUES (2, 'EMPLOYEE''S SERIOUS CONDITION', 55, 5);
INSERT INTO Persons (group_id, leave_reason, person_id, number_of_days)
VALUES (3, 'EMPLOYEE''S SERIOUS CONDITION', 66, 7);
INSERT INTO Persons (group_id, leave_reason, person_id, number_of_days)
VALUES (3, 'Family Vacation', 77, 2);
I want the output as follows;
Please kindly let me know how can I write a pivot query to obtain this output without hardcoding the values of LEAVE_REASON field?
I appreciate your help and thank you in advance!