Ignore NULL ratings. For each host and city, `host_avg` is the average rating of all reviews of that host's listings in the city; `city_avg` is the average rating of all reviews of listings in that city. Return hosts whose host_avg is strictly greater than city_avg. Return `city`, `host_id`, `host_avg` (ROUND 2), `city_avg` (ROUND 2). Order by `city`, `host_id`.
| Column | Type |
|---|---|
| listing_id | INTEGER |
| host_id | INTEGER |
| city | TEXT |
| listing_id | host_id | city |
|---|---|---|
| 1 | 10 | Goa |
| 2 | 10 | Goa |
| 3 | 11 | Goa |
| 4 | 12 | Manali |
| 5 | 13 | Manali |
| Column | Type |
|---|---|
| review_id | INTEGER |
| listing_id | INTEGER |
| rating | INTEGER |
| review_id | listing_id | rating |
|---|---|---|
| 1 | 1 | 5 |
| 2 | 1 | 4 |
| 3 | 2 | 5 |
| 4 | 3 | 3 |
| 5 | 3 | 4 |
| 6 | 4 | 4 |
| 7 | 4 | 5 |
| 8 | 5 | 2 |
| city | host_id | host_avg | city_avg |
|---|---|---|---|
| Goa | 10 | 4.67 | 4.2 |
| Manali | 12 | 4.5 | 3.67 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Normalize Artist Credits · Job Postings Filled Within 30 Days ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.