MySQL using notes (eight) statistical functions and packet data logging queries

Source: Internet
Author: User
Tags creative commons attribution

by Francis_hao Dec 17,2016

Statistical function Data Record query

Statistical functions

Statistical functions

Describe

Count ()

COUNT (*): Number of records in the statistics table (including null value fields)

Count (field): Number of records in the statistics table (excluding null value fields)

AVG ()

Calculate the average of field values

SUM ()

Calculate the sum of field values

Max ()

Query field value Maximum value

Min ()

Query field value Minimum value

mysql> Select function (field) [New_name] from table_name where conditions ;

You can take a name for the final field, or you can use the default.

Group Data Record Query

The meaning of grouping is to put together the same data records for a field.

Grouping for statistical functions

The first step is to introduce a function, Group_concat (), which implements the display of the specified field values in each group.

mysql> Select Group_concat (field) from table_name [where condition ] GROUP by field;

The following example shows the values of Row2 in each group when grouped with Row1.

Having clauses qualifying group queries

A display-like control that filters out data records that satisfy a condition.

The following example shows a record with a field data record greater than one in a group that is grouped by the Row1 field Row2.

Note

Take the last example to analyze the order in which SQL statements are executed.

1. Pass data records grouped in Row1 to 2 from table Tab_test

2. Select the required records from the data records received from 1 and pass to 3

3. Display data records from 2 that meet their own conditions


This article was authored by Liu Yinghao and licensed under the Creative Commons Attribution-NonCommercial use-Share 3.0 Chinese mainland license agreement in the same way. Welcome reprint, please specify the source:
Reprinted from: http://www.cnblogs.com/yinghao1991/

Reference

[1] Wang Feifei Triyang He Yaju "MySQL database application from getting started to mastering (second edition)" Beijing: China Railway Press, September 2014

MySQL using notes (eight) statistical functions and packet data logging queries

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.