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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现