当前位置:网站首页>MYSQL入门与进阶(十一)
MYSQL入门与进阶(十一)
2022-07-29 02:52:00 【小新爱编程】
查询结果集作为⼀个虚表直接参与查询
Eg:查询每个班级的学⽣个数,并根据个数倒序排序
Eg2:列出每个班的男⽣⼥⽣⽐例
/*子查询:
查询嵌套
- 查询结果作为虚拟的表直接使用
- 查询结果作为判断条件的值
- 查询结果作为赋值的值 update set a=值? 也可以用子查询
子查询:
查询的表的位置
查询的条件位置
delete的检索条件位置
update的检索条件的位置
update set赋值的位置也可以
insert书写值的位置也可以用 */
-- 查询结果作为表存在使用,必须起别名
17 -- 查询每个班级的学生个数,根据倒叙排序
18 select a.classname,count(b.studentid)
19 from class a
20 left join studentinfo b on a.classid=b.classid
21 group by a.classid,a.classname
22 order by count(b.studentid) desc
234 select * from(
25 select a.classname,count(b.studentid) as stucount
26 from class a
27 left join studentinfo b on a.classid=b.classid
28 group by a.classid,a.classname
29 )a
30 order by a.stucount desc
312 -- 列出每个班的男生和女生的个数比例
33 select nvcount/nancount,a.classid from(
34 select count(*) as nvcount,gender,classid
35 from studentinfo
36 where gender='女'
37 group by classid
38 )a
39 left join(
40 select count(*) as nancount,gender,classid
41 from studentinfo
42 where gender='男'
43 group by classid
44 )b on a.classid=b.classid
边栏推荐
- 【机器人学习】机械臂抓手matlab运动学与admas动力学分析
- MySQL operation database data error: fatal error encoded during command execution
- 并发模式之异步回调Future模式
- 三子棋(玩家+电脑)
- 明明开发薪资高,为什么我还是选了测试?
- Interpreting AI robots' pet raising and leading fashion trends
- Day 5 experiment
- Confusion matrix learning notes
- centos安装mysql8
- C陷阱与缺陷 第3章 语义“陷阱” 3.3 作为参数的数组声明
猜你喜欢
随机推荐
百度副总裁李硕:数字技术加持下中国劳动力成本上升是好事
Unable to start after idea installation
MySQL large table joint query optimization, large transaction optimization, avoiding transaction timeout, lock wait timeout and lock table
Redis配置缓存过期监听事件触发
OWT server source code analysis (4) -- video module analysis of mixer out
Summary of classic problems in Flink production environment
冰冰学习笔记:运算符重载---日期类的实现
TP5.0 小程序用户无需登录,直接获取用户手机号。
Interpreting AI robots' pet raising and leading fashion trends
What is SOA (Service Oriented Architecture)?
C陷阱与缺陷 第3章 语义“陷阱” 3.6 边界计算与不对称边界
Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers
C语言小项目 -- 通讯录(静态版+动态版+文件版)
Add a row to a specific location in the dataframe
Mongodb index (3)
Feedback function of conference OA
万字详解 Google Play 上架应用标准包格式 AAB
C陷阱与缺陷 第2章 语法“陷阱” 2.6 “悬挂”else引发的问题
C陷阱与缺陷 第3章 语义“陷阱” 3.3 作为参数的数组声明
会议OA之反馈功能









