SQL Group By

The GROUP BY statement groups rows with common values into summary rows. It is typically used with aggregate functions like COUNT(), SUM(), AVG(), MIN(), and MAX().



Tutorials dojo strip

SQL Group By Syntax

SQL




SQL Group By Example

Count patients by gender:

Using the Patients table, we can count how many patients belong to each gender.

SQL


Count medical records per patient:

This retrieves the number of medical records associated with each patient.

SQL




SQL GROUP BY with JOIN Example

Count appointments per doctor:

To analyze appointment counts for each doctor, we join the Appointments and Doctors tables:

SQL




SQL Group By Visual Diagram




SQL Group By Labs

Tutorials dojo strip