"MySQL must know" note (iv)

Source: Internet
Author: User

Data grouping

The GROUP BY clause can contain any number of columns and be nested so that the data is aggregated in the last set of groupings.

Each column listed in the GROUP BY clause must be a retrieval column or a valid expression (but not a clustered function), and if you use an expression in select, you must specify the same expression in the GROUP BY clause, and you cannot use an alias.

Each column in a SELECT statement must be given in the GROUP BY clause in addition to the clustered calculation statement.

The null values in the grouping column are separated into a separate set

Having is used to filter groups such as:

Select Cust_id,count (*) as orders from orders group by CUST_ID have Count (*) >=2;

Where the data is filtered before grouping, having to filter after grouping

Statement order: Select, from, where, group by, have, order by, limit

Establish sub-query skills: first establish and test the most internal query, and then use hard-coded data to build and test the outer query, and do not embed the subquery until it is OK.

"MySQL must know" note (iv)

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.