HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to SQL (SELECT)Tables (CREATE & INSERT)Filtering (WHERE)Sorting & LimitingAggregate FunctionsUpdate & DeleteJoins (JOIN)
REFERENCE
📖 Overview
🔎 Querying (SELECT)
🗃️ Creating a Table
✏️ Inserting & Modifying Data
🧲 Filtering (WHERE)
🔢 Sorting & Limiting
📊 Aggregate Functions
COUNT / SUM / AVGGROUP BY
🔗 Joins (JOIN)
SQL›REFERENCE›Aggregate Functions
📊

Aggregate Functions

COUNT, SUM, AVG and GROUP BY.

CommandDescription
COUNT / SUM / AVGCounts/sums/averages rows.
GROUP BYGroups and summarizes by value.

COUNT / SUM / AVG

Try it yourself →

Counts/sums/averages rows.

Syntax

SELECT COUNT(*), SUM(column) FROM table;

Description

COUNT(*) is row count, SUM is total, AVG is average, MIN/MAX is minimum/maximum.

Example

CREATE TABLE k(price INTEGER);
INSERT INTO k VALUES (10), (20), (30);
SELECT SUM(price) FROM k;

Expected output

60

When to use?

Summary/statistics.

GROUP BY

Try it yourself →

Groups and summarizes by value.

Syntax

SELECT column, COUNT(*) ... GROUP BY column;

Description

Groups rows with the same value; calculates an aggregate function for each group.

Example

CREATE TABLE k(city TEXT);
INSERT INTO k VALUES ('Milan'), ('Milan'), ('Berlin');
SELECT city, COUNT(*) FROM k GROUP BY city ORDER BY city;

Expected output

Berlin|1
Milan|2

When to use?

Summary by category (people per city, etc.).

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code