Comparison between distinct and group

Source: Internet
Author: User

The structure of table T3 is as follows: select * From t3id Edu age1 book 20 2 book 25 3 Book 30 4 Book 30 5 book 25 6 medium 15 7 medium 20 8 Medium 20 9 Specialized 20 10 specialized 20 11 specialized 20 12 specialized 30 13 expert 30 -------------------------------------- select distinct Edu, age from T3 order by age Edu age 15 in 20 in 20 in 20 in 25 in 30 In summary: 1, distinct Edu, age is to Edu, age two fields as one, as long as the EDU and age fields are the same, they will be treated as duplicate records; 2. Only one distinct or all can be used in select; 3. If distinct is used in select, all cannot be used; distinct cannot be used when all is used; it cannot exist at the same time; 4. If select distinct is specified, the items in the order by clause must appear in the selection list; ------------------------------- select Edu, age, count (*) as 'number' -- into from T3 -- where ID <10 -- filter condition recorded before the where group by Edu, age -- having grouping the group's filtering condition order by age Edu age Number of 15 1 in 20 1 in 20 2 in 20 3 in 25 2 in 30 2 in 30 2 In summary: 1. Distinct Edu, age regards the EDU and age fields as one. If the EDU and age fields are the same, the EDU and age fields are considered as the same group; 2. The column names in the select clause must be group columns or column functions. 3. The column names in the WHERE clause can be any fields in the table. 4. The column names in the having clause must be group columns or column functions;

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.