--分组的关键字
--group by
--where和having的区别
--where:分组前的条件查询
--having:分组后的过滤查询
--增删改查关键字
--insert into
--delete
--update set
--select
--创建表和删除表的关键字
--create、drop
--统计五个函数
--count()统计总数
--max()最大
--min()最小
--avg()平均
--sum()总和
--联表查询
/*
select * from 表1 别名
[inner]ioin 表2 别名
on 联表查询
*/
--内联查询
/*
inner join
*/
--外联查询
/*
左、右、全
左:left join
右:right join
全:full join
*/
select * from Student
--查询年龄比蒋欢大的学生信息
--查询到蒋欢的年龄
select * from Student where sage>(
select sage from Student where sname='蒋欢'
)
--查询大于平均年龄的学生信息
select * from Student where sage>(
--先查询出平均年龄
select avg(sage)from Student
)
--in:等于or 在指定值内
select * from score
--查询参加考试的学生信息
select * from Student where sid in(
--查询到有成绩的学生学号
select sid from score
)
--查询学号为1的学生信息
select * from Student where sid = 1
--查询学号1和2的学生信息
select * from Student where sid=1or sid =2
--查询学号1、2、3、4、5的学生信息
select * from Student where sid in(1,2,3,4,5)
--not in:不包括
--查询没有考试的学生信息
select * from Student where sid not in(
select sid from score
)
select * from score
--视图view
--查询所有学生的学生信息和成绩(包括没有成绩的)
select * from Student a
full join score b
on a.sid = b.sid
--创建视图
create view v_T283
as
select a.sid,a.sname,a.sage,a.ssex
b.js,b.bs from Student a
full join score b
on a.sid = b.sid
--使用视图
select * from v_T283
--请问创建视图可以:修改、添加吗?
--空值可以加1不?不可以直接加,但是可以转换后加
create view T_del
as
--删除视图
drop view v_T283