Second-Priciest Listing per Neighborhood
Problem
A property portal stores listings with an asking price and the neighborhood they sit in. For each neighborhood, find the listings whose asking price is the second-highest distinct price in that neighborhood. If several listings share that second-highest price, return all of them. Skip any neighborhood that has fewer than two distinct price levels. Return listing_id and neighborhood, ordered by listing_id.
Tables
Example rows — the live problem includes the full dataset.
| listing_id | asking_price | neighborhood |
|---|---|---|
| 1 | 70000 | Harborview |
| 2 | 80000 | Harborview |
| 3 | 80000 | Harborview |
Expected output
Your answer should return 4 rows with the columns listing_id, neighborhood.
Starter code (SQL)
SELECT *
FROM listings;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