Students per city
Easysqlgroup bycount
Return each city with its number of students (students). Sort from most to fewest, then by city name.
Tables
- students (id INTEGER, name TEXT, city TEXT, xp INTEGER)
Example 1
students
| id | name | city | xp |
|---|---|---|---|
| 1 | Mona | Cairo | 10 |
| 2 | Omar | Giza | 20 |
| 3 | Laila | Cairo | 30 |
| 4 | Hana | Aswan | 5 |
Expected result
| city | students |
|---|---|
| Cairo | 2 |
| Aswan | 1 |
| Giza | 1 |
Constraints
- 0 ≤ rows ≤ 1000
- The order of rows matters
Submit checks your solution against 10 tests, including hidden ones.
SQL
-- Write one SELECT query. Tables: students SELECT