Select sum (Population) from BBC
Sum is used in the population field of all returned records. The result is that only one result is returned for this query, that is, the total population of all countries.
Displays the total population and total area of each region:
Select region, sum (Population), sum (area)
From BBC
Group by region
First, return records are divided into multiple groups by region, which is the literal meaning of group. After grouping, use the aggregate function to calculate different fields (one or more records) in each group.
The total population and total area of each region are displayed. Only those regions with an area exceeding 1000000 are displayed.
Select region, sum (Population), sum (area)
From BBC
Group by region
Having sum (area)> 1000000
Here, we cannot use where to filter more than 1000000 of the regions, because such a record does not exist in the table.
Group by usage