Mysql avg (), count (), min ()/max (), sum () function _ MySQL

Source: Internet
Author: User
After the avg (), count (), min () max (), sum () functions of mysql are familiar with the simplest SQL statements, do you think the cmd form is particularly appealing to tao Huan (yan )!


Of course, we have a more intuitive and easy way to use SQL statements! That's visual edite )! Currently, many third-party visual operations are available.


I use navicat for mysql.

You can also use other third-party plug-ins.


Today, after basic SQL operations

Let's get familiar with simple aggregate functions!

Avg, as its name implies, is certainly a function for average calculation.

For example:

Calculate the average value of age in the table teacher_tab.

Select avg (age) FROM teacher_tab;


The count function calculates the number of occurrences, but does not calculate null.


For example:

Find the number of times a job appears in the teacher_tab.

Select count (job) FROM teacher_tab;

Min (), max (); are the maximum and minimum values respectively.
In the teacher_tab table, min and max use as to add the maximum and minimum values to the output:

Select min (age) as minimum value, MAX (age) as maximum value FROM teacher_tab;

And sum. this is the sum.

Select sum (age) AS age FROM teacher_tab;

Calculate the total age in the teacher_tab table.

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.