Garages With No Free Spaces
Problem
Table: `garages`
```text
+----------------+---------+
| Column Name | Type |
+----------------+---------+
| garage_id | int |
| garage_name | varchar |
| district | varchar |
| zone_code | varchar |
| opened_year | int |
| total_spaces | int |
+----------------+---------+
garage_id is the primary key for this table.
total_spaces is how many cars the garage can hold.
```
Table: `parking_sessions`
```text
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| session_id | int |
| garage_id | int |
| plate | varchar |
| entry_time | date |
| exit_time | date |
+-------------+---------+
session_id is the primary key for this table.
exit_time is NULL while the car is still parked.
```
A car is currently parked when its `exit_time` is NULL. Find every garage that is completely full right now — that is, the number of currently parked cars equals `total_spaces`.
Return `garage_id`, `garage_name`, `district`, `zone_code`, `opened_year`, and `parked_now`, ordered by `parked_now` descending, then `garage_name` ascending.
Tables
Example rows — the live problem includes the full dataset.
| garage_id | garage_name | district | zone_code | opened_year | total_spaces |
|---|---|---|---|---|---|
| 1 | Harbor Deck | Waterfront | WF | 2010 | 3 |
| 2 | Market Tower | Old Town | OT | 2005 | 3 |
| 3 | Station Lot | Midtown | MT | 2018 | 1 |
| session_id | garage_id | plate | entry_time | exit_time |
|---|---|---|---|---|
| 1 | 1 | AAA111 | 2024-01-15 | |
| 2 | 1 | BBB222 | 2024-01-20 | |
| 3 | 2 | CCC333 | 2024-01-10 | 2024-01-25 |
Expected output
Your answer should return 2 rows with the columns garage_id, garage_name, district, zone_code, opened_year, parked_now.
Starter code (SQL)
SELECT *
FROM garages;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock