How to use MySQL group

Source: Internet
Author: User

Q: How can I filter repeated items using group by? Could you give me an example?

 

Answer:

Example AA Table a B 123 10 123 12 1234 11 1234 14 first, group is used to group data, not to filter duplicate items. Duplicate deletion statement distinct uses this. The Select distinct (a) from AA result is the select a, sum (B) from AA group by a sum used for grouping by a 123 group. The result is that the B 123 22 1234 25 Statement aims to set a as the target and needs to know the total number of items with the same name in column B. Select a, count (B) from AA group by a count indicates the sum of the number of rows. The result is a B 123 2 1234 2 Statement, which indicates the total number of rows of an item with the same name.

 

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.