SQL Day Three

Source: Internet
Author: User

-"Complete SELECT statement and execution order (must be remembered)

5...select 5.2->distinct 7...top N [percent] 5.1-> column name aggregate function (1.2-> column name or expression)

1...1.1->from Table Name

2...where conditions

3...group by ... 4...having ...

6...order by ...

-"Practical Practice"

SELECT DISTINCT top 1 tsclassid,count (*) as number, AVG (tsage) as average age

From Tblstudent

Where tsgender= ' man '

GROUP BY TSCLASSID have tsclassid>3

ORDER BY average age desc

-"What is the order of execution?"

1. From Tblstudent

2. Where tsgender= ' man '

3. GROUP BY Tsclassid

4. Having tsclassid>3

5. Select

5.1 Tsclassid,count (*) as number, AVG (tsage) as average age

5.2 Distinct

6. Order BY average age desc

7, top 1

INNER JOIN (equivalent join) returns only rows that have the same join field in two tables

Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right table

Right join returns records that include all records in the right table and the junction fields in the left table

SQL Day Three

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.