MySQL GROUP by group and having filter grouping

Source: Internet
Author: User

1,group by creating a group

In MySQL group by sentence to note that must after where the order by

Select Order_code, COUNT (*) as product from order group by Order_code;

2,having Packet filtering

The WHERE clause can be replaced by the having, the difference is where the filter row, having a filter group; having all the where operators supported

However, where cannot be used to replace the having group filter

Select Order_code, COUNT (*) as product from order GROUP by Order_code have Count (*) >2;

The difference between having and where:

Where the data is grouped before filtering, having the data is grouped after filtering; where excluded rows are not included in the grouping (this may change the calculated value, thereby affecting the grouping that is filtered out of the HAVING clause based on those values)

MySQL GROUP by group and having filter grouping

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.