I have table in oracle sql.
CREATE TABLE person_status (
user_id number,
status_1 varchar(50),
status_1_date date,
status_2 varchar(50),
status_2_date date,
status_3 varchar(50),
status_3_date date,
status_4 varchar(50),
status_4_date date,
status_5 varchar(50),
status_5_date date)
)
INSERT INTO person_status VALUES (1,'Active','5/7/2024 12:15:20 PM','Suspend,'5/6/2024 05:20:09 PM','Active','11/28/2023 01:47:02 PM','Suspend','5/5/2024 12:10:08 PM','Suspend','3/27/2024 01:28:10 PM');
INSERT INTO person_status VALUES (2,'Active','5/7/2024 12:15:20 PM','Active,'5/6/2024 05:20:09 PM','Active','11/28/2023 01:47:02 PM','Active','5/5/2024 12:10:08 PM','Active','3/27/2024 01:28:10 PM');
INSERT INTO person_status VALUES (3,'Suspend','5/7/2024 12:15:20 PM','Suspend,'5/6/2024 05:20:09 PM','Suspend','11/28/2023 01:47:02 PM','Suspend','5/5/2024 12:10:08 PM','Suspend','3/27/2024 01:28:10 PM');
I want select data under these conditions:
- If the subscriber has all the offers in the suspend status, then
assign Yes to the offer that was given this status most recently. - If the subscriber has all the offers in the Active status, then
assign Yes to the offer that was given this status most recently. - If the subscriber has some offers in the active status and some
in the suspend status, then assign Yes to the offer which was
given the active status most recently.
I compared statuses and dates, but a long list came up to cover all possible cases