SQLab
LearnPracticeProblemsArenaLeaderboard
© 2026 SQLab · Tashkent
SQLab

Learn SQL right in the browser — nothing to install.

Platform

  • Learn
  • Practice
  • Problems
  • Arena
  • Leaderboard

Who it is for

  • Students
  • Teachers
  • Universities
© 2026 SQLab. All rights reserved.Made in Uzbekistan, for students.
LearnPracticeProblemsArenaLeaderboard
0/26

Basics

  • What is a database?
  • Your first SELECT
  • WHERE: picking the rows you need
  • IN, BETWEEN, LIKE and NULL
  • Sorting, LIMIT and DISTINCT

Calculations

  • Expressions, functions and CASE
  • Working with dates
  • COUNT, SUM, AVG, MIN, MAX
  • GROUP BY and HAVING

Joining tables

  • Keys and relations
  • INNER JOIN
  • LEFT JOIN and rows without a match
  • Several tables and the self join

Advanced queries

  • Subqueries
  • UNION, INTERSECT, EXCEPT
  • WITH: named queries
  • Window functions

Creating and changing tables

  • CREATE TABLE: types and constraints
  • INSERT, UPDATE, DELETE
  • ALTER, DROP, TRUNCATE
  • Designing a database well

Going professional

  • Indexes and EXPLAIN
  • Transactions and ACID
  • Views: saved queries
  • Functions, procedures and triggers
  • Users, privileges and backups
Learn/Calculations

COUNT, SUM, AVG, MIN, MAX

087 min

“How many students are there?”, “what is the average score?”, “how much does the most expensive product cost?” — questions like these turn many rows into one number. That is what aggregate functions are for.

The five main functions

Function What it does
COUNT(*) number of rows
SUM(column) total
AVG(column) average
MIN(column) smallest
MAX(column) largest
university· Try changing it
SELECT COUNT(*) AS students FROM students;
university· Try changing it
SELECT MIN(score), MAX(score), ROUND(AVG(score), 1) FROM grades;

Together with WHERE

Rows are picked first, then counted:

university· Try changing it
SELECT COUNT(*) FROM students WHERE funding = 'grant';

COUNT(*), COUNT(column) and COUNT(DISTINCT …)

  • COUNT(*) — every row;
  • COUNT(phone) — only rows where phone is not empty;
  • COUNT(DISTINCT city) — how many different cities.
university· Try changing it
SELECT COUNT(*) AS all_rows, COUNT(phone) AS with_phone, COUNT(DISTINCT city) AS cities FROM students;

Aggregates ignore NULL: AVG(scholarship) gives the average only over students who receive one.

An important rule

You cannot just put an aggregate next to a plain column:

SELECT city, COUNT(*) FROM students;   -- error!

The database does not know which city to show: the result is one row, but there are many cities. To count each city separately you need GROUP BY — the next lesson.

1Exercise

How many products does the store have, and what is their average price? Two columns: the count and the average price rounded to a whole number.


2Exercise

What is the total revenue (sum of fare) from completed (status = 'completed') trips?


Remember

  • COUNT, SUM, AVG, MIN, MAX — one value from many rows.
  • Aggregates skip NULL; COUNT(*) counts every row.
  • Need a plain column and an aggregate together? Use GROUP BY.
Previous lessonWorking with datesNext lessonGROUP BY and HAVING

Contents

  • The five main functions
  • Together with WHERE
  • COUNT(*), COUNT(column) and COUNT(DISTINCT …)
  • An important rule
  • Remember
LearnPracticeProblemsArenaLeaderboard

SQLab