14.SQL statement [6] aggregation, grouping

Source: Internet
Author: User

--====================== aggregation function ============================--Sum sum averaging avg. count max Max min minSelect    sumAmount asTotal Amount,avgAmount asaverage amount,MaxAmount asMaximum amount,minAmount asMinimum Amount,COUNT(*) asNumber of orders fromData--why run the Times wrong? Select Commodity, SUM (amount) as total amount from data--1 results after aggregation, can not correspond with multi-line data, so error--conclusion 1:select after using the aggregate function, it cannot be followed directly with other fieldsSelect SUMAmount asTotal Amount fromDataSelectCommodity fromData--====================== Group Statistics ============================--statistics, the total sales of each commodity, grouped by commodity category statistics--after the sum is used, it is not the sum of the sums of all the goods, but rather each group is represented by a--the sum of the interior--conclusion If there is aggregation behind 2:select, then if you want to follow the other fields, then the "other fields"--either group, or aggregate. SelectCommodities,SUMAmount asTotal Amount,AVGAmount asaverage amount,MAXAmount asMaximum amount,MINAmount asMinimum Amount fromDataGroup  byCommodity--grouping and performing aggregations---grouping statistics--====================== grouping filter ============================--count the total sales of orders of up to 100 per departmentSelectSales department,SUMAmount asTotal Sales fromDataGroup  bySales DepartmentSelectSales department,SUMAmount asTotal Sales fromDatawhereAmount>= - Group  bySales Department--where amount >=100 This filter is the filter for the data source before grouping. --statistics on the department information of more than 8000 of total salesSelectSales department,SUMAmount asTotal Sales fromDataGroup  bySales Department having SUMAmount>=8000--Having SUM (amount) >=8000 This filter is a filter that is done on the basis of grouping

14.SQL statement [6] aggregation, grouping

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.