FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses DBMS and SQL

CSE

Progress0 / 6 lessons
  1. 1. Why databases exist and what a table really is
  2. 2. SELECT, WHERE, ORDER BY and LIMIT
  3. 3. JOINs, with a worked two-table example
  4. 4. GROUP BY, aggregates, and HAVING vs WHERE
  5. 5. Keys and normalisation up to 3NF
  6. 6. Transactions, ACID, and what happens on a crash

Courses › DBMS and SQL

GROUP BY, aggregates, and HAVING vs WHERE

How grouping collapses rows, and the exact reason HAVING exists as a separate clause.

12 min read · Lesson 4 of 6 · Pro

Aggregates collapse many rows into one

An aggregate function reads a pile of rows and returns a single value. There are five you need.

  • COUNT(*) — how many rows
  • SUM(col) — total
  • AVG(col) — average
  • MIN(col) / MAX(col) — smallest and largest
SQL
SELECT COUNT(*) AS total_students, AVG(cgpa) AS avg_cgpa
FROM students;

One row out, no matter how many rows went in. That is the defining property.

The rest of this lesson is Pro

The free lessons of DBMS and SQL finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.