Aggregate functions of select statement query notes

Source: Internet
Author: User
-- Sum () Numeric (data type) Function Description: sums all non-null values in a specified Column
-- AVG () Numeric (data type) Function Description: calculates the average value for all non-null values in the specified Column
-- Min () number, character, date (data type)
Function Description: returns the minimum number, minimum string, and earliest date and time in the specified column.
-- Max () number, character, date (data type)
Function Description: returns the maximum number, the maximum string, and the latest date in the specified column.
-- Count ([distinct] *) any row-based data type (data type)
Function Description: Total number of records and records in the statistical result set, up to 2147483647 rows
-- Count_big ([distinct] *) any row-based data type (data type)
Function Description: similar to the count () function. However, because the return value uses the bigint data type, a maximum of 2 ^ 63-1 rows can be displayed.

-- Note: 1. the distinct keyword can remove duplicate values from the column.
-- 2. The SELECT statement is used to query the statistical value without column names. You can use the newly generated column alias.
-- 3. Used with group by. Each aggregate function generates a value for each group.
-- 4. When the distinct keyword is specified together with the aggregate functions sum (), count (), and AVG (), duplicate values can be eliminated from the column. Format: Aggregate Function (distinct column name)

Use northwind
Select * from products
Select AVG (unitprice) as avuplice from products
Select categoryid, AVG (unitprice) from products group by categoryid
Select * from [Order Details]
Select orderid, sum (Quantity) productnumber from [Order Details] group by orderid
Select min (unitprice) from [Order Details]
Select productid, min (unitprice) from [Order Details] group by productid
Select max (unitprice) from [Order Details]
Select productid, max (unitprice) from [Order Details] group by productid
Select count (*) from [Order Details] Where orderid = 10248
Select count (orderid) from [Order Details]
Select count (distinct orderid) as ordernumber from [Order Details]

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.