Aggregation

SELECT AVG(temp)
FROM collection_event;
SELECT MIN(latitude), MAX(latitude), AVG(latitude)
FROM sites;
SELECT Family, COUNT(DISTINCT(species)) as species_count 
FROM bee_traits 
GROUP BY family
ORDER BY species_count desc;
SELECT family, genus, COUNT(DISTINCT(species)) AS species_number 
FROM bee_traits 
WHERE family = "Melittidae"
GROUP BY family, genus
ORDER BY genus desc;

Filtering after aggregation

SELECT Family, COUNT(DISTINCT(species)) as species_count 
FROM bee_traits 
GROUP BY family
HAVING species_count > 3;

Only use grouped or aggregated fields in SELECT