Group by usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.