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.
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
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 →