Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Monday, Dec 7.Claim the deal

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 has 9 + 4 = 13 vacant days. Listing 2 has 5 vacant days. Listing 3 has 31 vacant days. The average is (13 + 5 + 31) / 3 = 16.33.


Accepted
27/94
Acceptance Rate28.7%
Test Cases
Input
-
Output
-
Expected
-