2_01_MSSQL课程_查询
查询
1.查询结果的别名
列 as 别名 (建议用这种)
列 别名
别名=列
Select sum(score1) as 成绩1,sum(score2)as 成绩2 from talScore
2.聚合函数
Avg() Count() Sum() Min()/Max()
Select max(score1),min(score1)from talScroe
“架构”信息,后面详细了解
3.Top截取 和 Order排序
Select * from talScore order by scoreId asc/desc,score2 asc/desc (升序和降序)
Select
top 3 *,
StuId as Demo,
from
talScore
order by
score1 desc
4.去除重复:Distinct
select * from tabScroe
select distinct score1 from talScroe order by score1
select distinct title,MiddleName from [SalesLT].[Customer] order by Title,MiddleName ——title,MiddleName联合起来去重
distinct 只能紧跟这select 后面,而且是对后面的所有的列都进行去重复操作