MySQL COUNT, group by, and mysqlcount

Source: Internet
Author: User

MySQL COUNT, group by, and mysqlcount

Group by is used to group the results, which facilitates statistics After grouping, so there will always be count followed

See the following table for example:


Group by ID, count the number of times each ID is repeated

SELECT yww_test.id, COUNT (id) as nFROM yww_testGROUP BY yww_test.id


Record duplication can be found as follows:

SELECT id, COUNT (*) AS nFROM yww_testGROUP BY yww_test.idHAVING COUNT (*)> 1;

Count (*) is used to count the number of rows in each group.

Note:

Count (*) returns the total number of all existing rows in the table, including rows with null values. However, count (column name) returns the total number of all rows except null in the table (columns with default values are also included ).
Distinct column name. The result is the result after the value is null and the duplicate data is deleted.

Reference: http://www.111cn.net/database/mysql/53202.htm

For more group by, see: http://blog.csdn.net/xxpyeippx/article/details/8059910



Related Article

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.