SQL Aggregate Operators

What
SQL aggregate operators allow us to gather information about groups of tuples.

COUNT(*)
This aggregate operator simply counts the total number of tuples in a set SELECT COUNT(*) FROM Sailors s

COUNT([DISTINCT] A)
In conjunction with the DISTINCT set operator, we can get the count of all distinct values of the attribute A SELECT COUNT(DISTINCT s.sname) FROM Sailors s This query returns the total number of distinct sailor names in the club

SUM([DISTINCT] A)
Note that the brackets [] denote that the DISTINCT operator is optional SELECT SUM(s.rating) FROM Sailors s

AVG([DISTINCT] A)
This aggregate operator simply takes the average over a column of the tuples in a set SELECT AVG(s.rating) FROM Sailors s

MAX(A)
This aggregate operator takes the max of a column of the tuples in a set SELECT MAX(s.rating) FROM Sailors s

MIN(A)
This aggregate operator takes the min of a column of the tuples in a set SELECT MIN(s.rating) FROM Sailors s