——————-数据查询————————————
——————查询输入——–
——设置查询别名 as 或者 =
select StuID as 学号, 姓名=StuName,StuSex as 性别 FROM StuInfo
——查看数据“性别——学员姓名”
select StuSex+’‘+StuName as ‘性别学员姓名’ FROM StuInfo
——ALL关键字
select ALL StuID,StuName,StuSex FROM StuInfo
——DISTINCT 关键字消除查询数据重复的数据
select DISTINCT StuID FROM StuInfo
——Top n 显示前面n条数据的值
select top 2 StuID FROM StuInfo
——Top n PERCENT 显示前面n%条数据的值
select top 2 PERCNET StuID FROM StuInfo
——————结果筛选————-
—–WHERE 条件筛选
select * from StuInfo where StuSex=’男’ and StuName<>’王五’
select * from StuInfo where StuId between 2 and 4
select * from StuInfo where StuId NOT BETWEEN 2 AND 4
select * from StuInfo where StuId IN (1,3,5)
select * from StuInfo where StuId not in (1,3,5)
—-like 模糊筛选 通配符%_[][^]
select DISTINCT StuName from StuInfo where StuName like ‘%易%’
——ORDER BY 对查询结果排序 ASC 升序 DESC降序
select DISTINCT * from StuInfo ORDER BY StuId DESC, StuName ASC
——-使用sum函数计算字段累加和
select sum (Score) as 语文总和
from StuMarks WHERE Subject =’语文’
——-使用avg函数计算字段平均值
select avg(Score) as 数学
from StuMarks WHERE Subject =’数学’
——-使用Max和min求最大最小值
select max(score) as 最高分,min (score) as 最低分
from StuMarks
——-group by 分组
select Subject as 科目 ,Count(*) as 人数
from StuMarks Group by Subject
——-Having 聚合条件
select Subject as 科目,AGE(Score) as 平均分数
FROM StuMarks GROUP BY Subject
HAVING AVG (Score) >75