数据库
首页 > 数据库> > SQL 数据库高级子查询

SQL 数据库高级子查询

作者:互联网

--分组的关键字
--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

 

标签:--,数据库,sid,查询,Student,SQL,where,select
来源: https://www.cnblogs.com/huangyanda/p/16310569.html