MySQL COUNT and GROUP by

Source: Internet
Author: User

Group BY is used to group the results, which is easy to count after grouping, so there will always be count followed by

For example, the following table:


Group by ID, count each ID repeated several times

SELECT Yww_test.id,count (ID) as Nfrom yww_testgroup by yww_test.id


To find out the duplicate records can be like this.

SELECT Id,count (*) as Nfrom Yww_testgroup by Yww_test.idhaving COUNT (*) >1;

where COUNT (*) is the count of how many rows each group has

Attention:

COUNT (*) returns the total number of rows that exist in the table, including rows with a value of NULL, whereas count (column name) returns the total number of all rows except null in the table (columns with default values will also be counted).
Distinct the column name, the result will be the result of dropping the value null and repeating the data

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

For more Group by please refer to: http://blog.csdn.net/xxpyeippx/article/details/8059910



MySQL COUNT and GROUP by

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.