Remember to

Aggregation

SELECT AVG(weight)
FROM surveys;
SELECT MIN(weight), MAX(weight), AVG(weight)
FROM surveys;
SELECT species_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
GROUP BY species_id;
SELECT species_id, plot_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
GROUP BY species_id, plot_id;
SELECT species_id, plot_id, COUNT(species_id)
FROM surveys;
SELECT species_id, plot_id, COUNT(*)
FROM surveys;
SELECT species_id, plot_id, COUNT(*) as count
FROM surveys;

Do Exercise 7 - COUNT.

Filtering after aggregation

SELECT species_id, plot_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
GROUP BY species_id, plot_id
HAVING MIN(weight) IS NOT NULL;
SELECT species_id, plot_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
WHERE weight > 10
GROUP BY species_id, plot_id
HAVING MIN(weight) IS NOT NULL;

Only use grouped or aggregated fields in SELECT

SELECT species_id, plot_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
WHERE weight IS NOT NULL
GROUP BY species_id, plot_id;
SELECT species_id, plot_id, MIN(weight), MAX(weight), AVG(weight)
FROM surveys
WHERE weight IS NOT NULL
GROUP BY species_id;