模糊查询和聚合函数

模糊查询
在大批量的数据中进行,模糊条件的查找,只知道部分条件(单个字符,单个数字)
不明确的、大概的

通配符
他可以代替一个或多个真正的字符,与“like”一起用
一个字符
% 任意长度的字符
[] 括号范围中的
[^] 不在括号范围中的一个字符
select * from Student where StudentName like '冯_'
select * from Student where Address like '%舍%'
select * from Student where StudentNo like 'S110100[1-9]'
select * from Student where StudentNo like 'S110100[^1-2]'

 

查询空
select * from Student where Email is null

select * from Student where Email = ''


between关键字查询区间的(数值只能从小到大)
select * from Result where StudentResult Between 90 and 100


in关键字(值必须准确)
select StudentName as 姓名,Address as 地址
from Student
where Address in('天津市河西区','河南省南阳市','学生宿舍')


聚合函数:对一组值进行计算,并返回计算后的值,具有统计数据的作用
--求和SUM()
select SUM(StudentResult) AS 总成绩 from Result
--AVG平均分
--查询成绩表中的平均分、最大值和最小值
select AVG(StudentResult) as 平均分,MAX(StudentResult) as 最大值,MIN(StudentResult) as 最小值
from Result
where StudentResult >= 60

--求和
select COUNT(*) from Result
where StudentResult >= 60

--找到学员S1101004的成绩
select * from Student
select * from Result where StudentNo = 'S1101004'

 

 

 

 

 

 

 

 

 

posted @ 2018-01-10 13:55  H丶  阅读(197)  评论(0编辑  收藏  举报