sql-function Avg,count,max,min,sum

Source: Internet
Author: User

Common functions

AVG (average) COUNT (count) MAX (maximum value) MIN (minimum value) SUM Sum

The syntax for applying a function is:

Select from "table name";

For example, if we were to find the sum of the Sales fields from our demo table,

SELECT SUM  from Store_information;

Results:

2750

2750 represents the sum of all Sales fields: 1500 + 250 + 300 + 700.

In addition to the use of functions, SQL can also do simple mathematical operations, such as add (+) and minus (-). For the text class data, SQL also has several functions of word processing, such as text connection (concatenation), text trimming (trim), and sub-string (substring). Different databases have different syntax for these functions, so it is best to refer to the information of the database you are using to determine how these functions are used in that database.

For example, if we want to find out how many of the Store_name columns in our demo table are not blank data,

SELECT COUNT  from WHERE are not NULL;

Results:

4

COUNT and DISTINCT are often used together in order to find out how many different data are in the table (as to what is actually unimportant). For example, if we were to find out how many different store_name we had in our table, we would break in,

SELECT COUNT (DISTINCT from Store_information;

Results

3

sql-function Avg,count,max,min,sum

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.