Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Students per city

    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

    idnamecityxp
    1MonaCairo10
    2OmarGiza20
    3LailaCairo30
    4HanaAswan5

    Expected result

    citystudents
    Cairo2
    Aswan1
    Giza1

    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
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.