Analytics

Aggregates

Aggregates - Count

SELECT COUNT(*) as "count"
FROM teachers;
count
3

Aggregates - Max/Min

SELECT MAX(years) as "max", MIN(years) as "min"
FROM curriculeon.teacher_meta
max min
11 4

Aggregates - Sum

SELECT SUM(years) as "sum"
FROM curriculeon.teacher_meta
sum
19

Aggregates - Group_Concat

SELECT GROUP_CONCAT(' ', first_name, ' ', last_name) as "group_concat"
FROM curriculeon.teachers;
group_concat
John Smith, Tabitha Schultz, Jane Herman

Group By

SELECT GROUP_CONCAT(' ', first_name, ' ', last_name) as "teachers", years
FROM curriculeon.teachers t
JOIN curriculeon.teacher_meta tm
  ON t.id = tm.teacher_id
GROUP BY tm.years;
teachers years
John Smith, Tabitha Schultz 4
Jane Herman 11

Having

SELECT s.name, COUNT(a_s.assignment_id) as "assignments given"
FROM curriculeon.students s
JOIN curriculeon.assignment_student a_s
  ON s.id = a_s.student_id
GROUP BY s.name
HAVING COUNT(a_s.assignment_id) > 1;
name assignments given
Linnell McLanachan 2

DBA corgis hope you’re HAVING a blast!