Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    SQLSQL

    First questions to the data

    • What are SQL and databases?
    • SELECT: choosing columns
    • WHERE: filtering rows
    • ORDER BY and LIMIT: sort and take the top

    Summarizing and grouping

    • Aggregates: COUNT, SUM, AVG
    • GROUP BY and HAVING
    • CASE, COALESCE and text functions

    Joining tables

    • Keys and relationships
    • INNER JOIN
    • LEFT JOIN: leave nobody out
    • Three-table joins and self joins
    • Subqueries and CTEs

    Building tables and changing data

    • CREATE TABLE and constraints
    • INSERT, UPDATE and DELETE
    • Transactions: all or nothing
    • SQL injection: the most dangerous mistake

    Professional level

    • Indexes: why is my query slow?
    • Window functions: rankings and totals without losing rows
    • Designing tables: normalization
    • Project: analytics for a learning platform
    SQL

    Professional level · Lesson 20 of 20

    Project: analytics for a learning platform

    Revenue per course, completion rates and a leaderboard, using everything you've learned.

    15 minutes3 games

    You're now the platform's data analyst, and management wants three numbers for the next meeting. Each exercise is a real question that combines several things you've learned.

    Same tables: students, courses and enrollments. Always start with a small exploration before writing the solution.

    SQL
    -- Explore first: one row per enrollment with everything joined
    SELECT s.name, c.title, c.price, e.progress
    FROM enrollments e
    JOIN students s ON s.id = e.student_id
    JOIN courses c ON c.id = e.course_id
    ORDER BY c.title, s.name;

    1. Revenue per course

    Exercise

    For each course with enrollments: title and its revenue as revenue (price × number of students), highest first, ties by title.

    Expected result:
    title | revenue
    JavaScript | 1350
    Python | 1200
    React | 600
    SQL | 600
    HTML & CSS | 0
    SQL
    SELECT c.title
    FROM enrollments e
    JOIN courses c ON c.id = e.course_id
    

    2. Completion rate

    Exercise

    For each course with enrollments: title, the number of students students, and how many finished (progress = 100) as finished. Order by title.

    Expected result:
    title | students | finished
    HTML & CSS | 3 | 2
    JavaScript | 3 | 0
    Python | 3 | 1
    React | 1 | 0
    SQL | 2 | 0
    SQL
    SELECT c.title
    FROM enrollments e
    JOIN courses c ON c.id = e.course_id
    

    SUM(CASE WHEN … THEN 1 ELSE 0 END) is conditional aggregation: several different counts in one query. PostgreSQL has a shorter form: COUNT(*) FILTER (WHERE progress = 100).

    3. The leaderboard

    Exercise

    The top 3 students by XP: place (using RANK), name, xp, and their number of courses as courses (even if zero). Exclude students whose XP is NULL.

    Expected result:
    place | name | xp | courses
    1 | Nour | 410 | 2
    2 | Laila | 320 | 3
    3 | Mariam | 275 | 2
    SQL
    SELECT s.name, s.xp
    FROM students s
    

    Important

    In real projects these queries become a view (CREATE VIEW course_revenue AS …) so everyone shares one definition, or a materialized view refreshed hourly when data is large. That's what keeps dashboard and report numbers consistent.

    Interview question

    A common practical interview question: "Get the top 3 best-selling products in each category this month." How would you approach it?

    Learn more from

    • PostgreSQL docs: Aggregate functions (FILTER)postgresql.org
    • PostgreSQL docs: CREATE VIEWpostgresql.org
    • Mode: SQL window functionsmode.com

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousDesigning tables: normalization🎉 خلّصت SQL!
    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.