--====================== 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