Table: rental_availability
+----------------+----------+ | Column Name | Type | +----------------+----------+ | listing_id | integer | | available_from | date | | available_to | date | +----------------+----------+
(listing_id, available_from)is the primary key. Each row is an availability window for a listing.
Write a query to compute the average number of vacant days across all listings. For each listing, sum the total available days across all its windows, exclusive of the end date, then average that total across listings. Round the result to 2 decimal places and return it as avg_vacant_days.
The result format is shown below.
Example
Input:
rental_availability table: +------------+----------------+--------------+ | listing_id | available_from | available_to | +------------+----------------+--------------+ | 1 | 2023-01-01 | 2023-01-10 | | 1 | 2023-02-01 | 2023-02-05 | | 2 | 2023-01-15 | 2023-01-20 | | 3 | 2023-03-01 | 2023-04-01 | +------------+----------------+--------------+Output:
+-----------------+ | avg_vacant_days | +-----------------+ | 16.33 | +-----------------+Explanation:
Listing 1 has9 + 4 = 13vacant days. Listing 2 has5vacant days. Listing 3 has31vacant days. The average is(13 + 5 + 31) / 3 = 16.33.
Accepted
27/94
Acceptance Rate28.7%
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
-
Output
-
Expected
-