MySQL in Count (), group by uses

Source: Internet
Author: User

Count () In the statistics table or in the array record

COUNT (*) returns the number of rows retrieved, regardless of whether the value contains null

COUNT (column_name) returns the count of rows that are NOT NULL for column column_name

For example, query the number of user comments for a recipe for an activity:

SELECT COUNT  from WHERE id=530787 and Idtype='paiid' 

Now you want to query the number of comments for each user and display them in reverse order of the number of comments:

SELECT COUNT  as  from WHERE id=530787 and Idtype='paiid' GROUP  by ORDER  by DESC

Of course, you can also query the number of comments more than 5:

  #在group by after using the HAVING clause to qualify the conditions for grouping 
SELECT count (Authorid) as C, authorid,author from uchome_ Comment where id530787 and idtype= '

17:20:54 Continuous Update

MySQL in Count (), group by uses

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.