Where there's more than one
- O(n) · Medium
- Full plan
- SQL
- grouping
- nulls
Problem
The store wants to open a pickup location in every city where it has more than one customer. For a single customer it isn't worth it.
Show the city and how many customers live there, in that order. Nothing is known about the people who never said where they live: however many there are, together they don't make a city.
What it has to return
These rows, in any order
| city | how_many |
|---|---|
| Austin | 2 |
| Denver | 3 |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT city
FROM customers
GROUP BY cityIt opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.
More O(n) challenges
- Who owes grades?SQL · grouping · joins · nulls
- A two-credit 10SQL · grouping · joins · decimals
- Aisle by aisleSQL · grouping · conditionals
- Averages that mean somethingSQL · grouping · joins
- Bunched up or spread outSQL · grouping · joins · sorting
- Chairs for parents' nightSQL · grouping · joins · sorting