You're an analyst at UrbanNest, a real estate agency. Appraisers need a way to find comparable listings: two apartments in the same district with the same number of rooms make a good pair for comparing prices. The listings table contains active apartment listings.
For each district, find every pair of listings with the same number of rooms. Return each pair exactly once, placing the listing with the smaller ID first. If a district has three matching listings, include all three possible pairs. Exclude listings whose room count is unknown (NULL).
Return these columns:
- district — the district;
- rooms — the number of rooms;
- listing_a — the ID of the listing with the smaller ID in the pair;
- listing_b — the ID of the listing with the larger ID in the pair;
- price_gap — the absolute difference between the listing prices (without rounding).
Sort by district alphabetically, then by listing_a in ascending order, then by listing_b in ascending order.
districtroomslisting_alisting_bprice_gapShowing the first 3 rows of the sample — the full sample comes with Premium
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in