模糊查询和聚合函数

一.模糊查询

1.1 通配符

通配符 解释 示例
_ 一个字符 A like 'c_' 符合如 cs cd

%

任意长度 B like 'co%' 符合 const coke
[] 括号中所指定范围内的一个字符 C like '9W0[1-2]' 符合 9w01 9w02
[^] 不在括号中所指范围内的任意个字符

D like '9w0[^1-2]' 符合 9w03

1.2 使用LIKE进行模糊查询

select * from Stidents where Sname like 'zhang%'

1.3 使用BETWEEN在某个范围内进行查询]

select * from Score where Score between 60 and 80    (包含60和80)

1.4 使用IN在列举之内进行查询

select Sname as 学生姓名 from Student where Address

IN('北京','广州','上海') order by Address

二.聚合函数

2.1 SUM()函数

返回所有表达式中所有数值的总和

select SUM(SCore) AS 学号为23的学生总分 from SCore where StudentID=23

2.2 AVG()函数

返回表达式中所有数值的平均值

select AVG(SCore) as 平均成绩 from SCore where SCoore>=60

2.3 MAX()函数和MIN()函数

返回表达式中所有数值的最大值和最小值

select MAX(SCore) as 最大成绩, MIN(SCore) as 最小值 from SCore where SCoore>=60

2.4 COUNT()函数

返回提供的组或记录集中的计数

select COUNT(Score) as 分数记录数 from SCore

  

原文地址:https://www.cnblogs.com/huanghui-1243/p/7723895.html