sql第三天

-》完整的select语句及执行顺序(必须记住)

5...select 5.2->distinct 7...top n [percent] 5.1->列名 聚合函数(1.2->列名或表达式)

1...1.1->from 表名

2...where 条件

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

6...order by ...

-》实际练习

select distinct top 1 tsclassid,COUNT(*) AS 人数,avg(tsage) as 平均年龄

from tblstudent

where tsGender='男'

group by tsclassid having tsclassid>3

order by 平均年龄 desc

-》问执行顺序是如何?

1、from tblstudent

2、where tsGender='男'

3、group by tsclassid

4、having tsclassid>3

5、select

5.1 tsclassid,COUNT(*) AS 人数,avg(tsage) as 平均年龄

5.2 distinct

6、order by 平均年龄 desc

7、top 1

inner join(等值连接) 只返回两个表中联结字段相等的行

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录

right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录

 

posted @ 2016-12-18 16:45  菜鸟,你好  阅读(142)  评论(0编辑  收藏  举报