Hi
I'm a little stuck with an SQL qurey I need to write. Can you guys give some guidance?
Here's the requirement:
You have a stays table with the below structure (with examples of 2 stays):
stay_id event_type date
1563071 check-in 2019-03-21
1563071 check-out 2019-03-23
1554074 check-in 2019-03-23
1554074 check-out 2019-03-24
- Each stay has exactly 2 rows: 1 for check-in and 1 for check-out.
- All the data in the table is correct and complete (stay_id is unique, no missing rows, check-out
date is always after the check-in date).
Write an SQL query to retrieve the average length of stay (number of nights between the
check-in and check-out).