Hi developers,
I do have a question I can't resolve... Maybe there's someone who can help me on this one?
I have a table with data regarding persons who have subscribed to something. In most cases, there are two people who have subscriptions under the same subscription_id. In some cases (see example) one of the persons stops the subscription earlier than the second person.
What I would like is an overview of the date when the person who stops the subscription first, the subscription_id and the person_nr. Or, in case of only one subscriber, the same information but for this one person.
My sample data:
Drop table b;
create table B (reference_date date, subscription_id int, person_nr int)
Insert into B values ('2022-01-31',1000,15)
Insert into B values ('2022-01-31',1000,16)
Insert into B values ('2022-02-28',1000,15)
Insert into B values ('2022-02-28',1000,16)
Insert into B values ('2022-03-31',1000,15)
Insert into B values ('2022-03-31',1000,16)
Insert into B values ('2022-04-30',1000,15)
Insert into B values ('2022-05-31',1000,15)
Insert into B values ('2022-06-30',1000,15)
Insert into B values ('2022-07-31',1000,15)
Insert into B values ('2021-01-31',1001,18)
Insert into B values ('2021-01-31',1001,19)
Insert into B values ('2021-02-28',1001,18)
Insert into B values ('2021-02-28',1001,19)
Insert into B values ('2021-03-31',1001,19)
Insert into B values ('2021-04-30',1001,19)
Insert into B values ('2021-05-31',1001,19)
Insert into B values ('2022-06-30',1002,50)
Insert into B values ('2022-06-30',1002,51)
Insert into B values ('2022-07-31',1002,50)
Insert into B values ('2022-07-31',1002,51)
Insert into B values ('2022-08-31',1002,50)
Insert into B values ('2022-08-31',1002,51)
Insert into B values ('2022-09-30',1002,50)
Insert into B values ('2022-09-30',1002,50)
Insert into B values ('2022-10-31',1002,50)
Insert into B values ('2022-08-31',1003,25)
Insert into B values ('2022-09-30',1003,25)
Insert into B values ('2022-10-31',1003,25)
My desired outcome: