use studentSys
select * from studentTest
update studentTest set studentName = '张氏' where studentId = 2
-- 模糊查询
-- like %
-- 查询姓赵的人
select * from studentTest where studentName like '李%'
-- 查询姓名中带有c的人名
select * from studentTest where studentName like '%c%'
-- like _
-- 查询第五个字符是c的人名
select * from studentTest where studentName like '____c%'
-- like []
-- 查询以c或者是b开头的人信息
select * from studentTest where studentName like '[cb]%'
-- 查询姓陈鲁小的人信息
select * from studentTest where studentName like '[陈鲁小]%'
-- like [^]
-- 查询不是以c或b开头的人信息
select * from studentTest where studentName like '[^cb]%'
-- 查询不是姓张李
select * from studentTest where studentName like '[^张李]%'
-- 查询人名为_的人信息
select * from studentTest where studentName like '%[_]%'
-- ********************** in **************************
-- 查询上海和武汉的学生(in 的情况完全可以用or替换,in并且可以使用子查询)
select * from studentTest where studentAddress in ('武汉','上海')
select * from studentTest where studentAddress = '武汉' or studentAddress = '上海'
-- ******************** between ************************
-- 在where子句当中,可以使用between运算符在两个值之间进行筛选
-- select 字段 from table_name where 字段 between 值1 and 值2
-- 值1 <= 值2
-- between 可以用and替换掉
-- 用于数字类型的筛选
--用于时间日期类型的筛选
-- 查询学号在3到6之间的
select * from studentTest where studentId >=3 and studentId <= 6
select * from studentTest where studentId between 3 and 6
-- select * from studentTest where studentId between 6 and 3 (between and 的两个值的顺序)
-- 查询学生的出生年日范围(出生日期在1996-1-1 到 1996-12-31之间的)
select * from studentTest where studentBorDay between '1996-1-1' and '1996-12-31'
-- ******************** 聚合函数(使用student score course classes表) ***********************
-- sum 求和
-- max 最大值
-- min 最小值
-- avg 平均值 (一列当中非null的平均值)
-- count 求总数 (统计个数)
-- 使用了聚合函数的列只能够在聚合函数中,不能够包含其他列
-- 聚合函数不能够最为where子句的直接搜索条件
-- 成绩综合(Java课程分数综合)
select SUM(scores)as 'Java总分' from Score where courseId = (select courseId from Course where courseName = 'Java')
-- java课程最高分
select MAX(scores) as 'Java最高分' from Score where courseId = 1
-- Java平均分
select AVG(scores) as 'Java平均分' from Score where courseId = 1
-- java最低分
select MIN(scores) as 'Java最低分' from Score where courseId = 1
-- 学习Java的人数
select COUNT(scores) as '学习Java人数' from Score where courseId = 1
-- 查询Java课程最高分的学号
-- 选择列表中的列 'Score.stuId' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
-- select MAX(scores),stuId from Score where courseId = 1
select MAX(scores),MIN(scores) from Score where courseId = 1
-- ********************** group by 分组查询 ****************************
-- select 字符 from table_name group by 字段1 字段2
-- null值时候会将所有的null作为一组
-- 求出每一门课的最高分
select courseId as '课程ID' ,MAX(scores) as '该课程最高分' from Score group by courseId
-- 大于九十分
select courseId as '课程ID' ,MAX(scores) as '课程最高分' from Score where scores > 90 group by courseId
-- 平均分大于80
select courseId as '课程ID' ,AVG(scores) as '课程分数' from Score group by courseId having avg(scores) > 80
/****************************************************************
having 和 where 区别
-- 执行顺序的不同
-- where 分组之前 having 分组之后使用
-- having 必须和group by 一起使用,放在group by之后
-- where存在的话放在 group by之前
-- having 之后可以使用聚合函数,where后面不行
-- having 后面使用聚合函数 或者group by分组字段
*/
-- ********************** 查询语法 ****************************************
-- select 字段 from table_name where 条件 group by 字段 having 条件(聚合函数或者group by 分组字字段) order by 字段 规则