You can aggregate repeated records of a field
SELECT <column-name> FROM <table-names>
GROUP BY <column-name[s]> HAVING <condition>;
You can use the GROUP BY
command to aggregate repeated columns and display
them as a resuming.
It is most commonly used with other aggregate functions like COUNT()
When using multiple selected columns and only one agreggator the group by
must reference the other columns
HAVING
: Perform additional filtering after the aggregation and summary- Unlke
WHERE
you can use aggregate functions afterHAVING
- Unlke
You can perform some extra filtering after the aggregation with the HAVING
command, this command is different from WHERE
because it does it's
filtering after the aggregation
It also must come before the sortin ORDER BY
command
SELECT country_of_birth, COUNT(*) FROM person
GROUP BY country_of_birth HAVING COUNT(*) > 5
ORDER BY country_of_birth;
If you want to know what are the minimum values for each aggregation field
SELECT brand, model, MIN(prince) FROM car
GROUP BY brand, model;