Counts the number of rows COUNT(*)
SELECT COUNT(*) FROM pet;
Counts how many pets each owner has:
SELECT owner, COUNT(*) FROM pet GROUP BY owner;
Use of COUNT() in conjunction with GROUP BY:
Number of animals per species:
SELECT species, COUNT(*) FROM pet GROUP BY species;
Number of animals per sex:
SELECT sex, COUNT(*) FROM pet GROUP BY sex;
Number of animals per combination of species and sex:
SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
When performed just on dogs and cats, looks like this:
SELECT species, sex, COUNT(*) FROM pet
WHERE species = 'dog' OR species = 'cat'
GROUP BY species, sex;
Or, if you wanted the number of animals per sex only for animals whose sex is known:
SELECT species, sex, COUNT(*) FROM pet
WHERE sex IS NOT NULL
GROUP BY species, sex;