Home › coding › sql › sql groupby

Sql Groupby — Free Sql Tutorial

Learn Sql Groupby in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

TL;DR: Learn Sql Groupby in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

Sql Groupby in Sql

GROUP BY groups rows that have the same value in one or more columns, then applies aggregate functions (COUNT, SUM, AVG, MAX, MIN) to each group separately. This is the foundation of data analysis in SQL.

Example: Instead of the average marks of ALL students, GROUP BY city gives the average marks of students FROM EACH CITY. Instead of total sales, GROUP BY product gives total sales PER PRODUCT.

Rule: Any column in the SELECT that is NOT an aggregate function MUST appear in the GROUP BY clause. This is one of the most common SQL mistakes beginners make.

Sql Groupby — Syntax

SELECT column, AGG_FUNCTION(column)
FROM table
GROUP BY column;

-- Example:
SELECT city, COUNT(*) AS student_count, AVG(marks) AS avg_marks
FROM students
GROUP BY city;

Learn Sql Groupby step by step with Syllab's free interactive Sql tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Sql course →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12