I have the following reservation data:
Site | Reservation | Arrival | Departure | Category |
---|---|---|---|---|
AIRBNB_1 | 1234 | 2023-01-01 | 2023-01-02 | GUEST |
AIRBNB_1 | 1234 | 2023-01-02 | 2023-01-03 | GUEST |
AIRBNB_1 | 1234 | 2023-01-03 | 2023-01-07 | OWNER |
AIRBNB_2 | 5678 | 2023-01-15 | 2023-01-17 | GUEST |
AIRBNB_3 | 9123 | 2023-02-01 | 2023-02-02 | COMP |
I need to add a new "Umbrella Category" that takes into account the Category column across the Site + Reservation.
Site | Reservation | Arrival | Departure | Category | Umbrella Category |
---|---|---|---|---|---|
AIRBNB_1 | 1234 | 2023-01-01 | 2023-01-02 | GUEST | OWNER |
AIRBNB_1 | 1234 | 2023-01-02 | 2023-01-03 | GUEST | OWNER |
AIRBNB_1 | 1234 | 2023-01-03 | 2023-01-07 | OWNER | OWNER |
AIRBNB_2 | 5678 | 2023-01-15 | 2023-01-17 | GUEST | GUEST |
AIRBNB_3 | 9123 | 2023-02-01 | 2023-02-02 | COMP | COMP |
Unfortunately, I cannot group because I need all records. Is there a function or possible partition that would allow me to assign an umbrella category based on the category column? I have the below query, but it doesn't allow me to take into account Site + Reservation columns (which is needed because the first three lines are one reservation. Any insight is much appreciated.
select
[Site],
Reservation,
Arrival,
Departure,
Category,
case
when Category in ('GUEST', 'OWNER') then 'OWNER'
when Category in ('OWNER', 'COMP') then 'OWNER'
when Category in ('GUEST', 'COMP') then 'GUEST'
else Category end as [Umbrella Category]
from #Reservations