AnalystPath

Second-Priciest Listing per Neighborhood

SQLMediumMid level~15 min

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.

listings
listing_idasking_priceneighborhood
170000Harborview
280000Harborview
380000Harborview

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

Related SQL questions