Mysql查询语句练习题
表结构示意图:
题目:
7、查询学过“1”并且也学过编号“2”课程的同学的学号、姓名;
select student.sid,student.sname from student right join (select New.student_id as ID,count(New.course_id) as Num from (select * from score where course_id=1 or course_id=2) as New group by New.student_id having Num=2) as A on student.sid=A.ID;
8、查询学过“小多”老师所教的课的同学的学号、姓名;
(1)查询出小多老师的课程数量 select count(course.cid) as Num from course left join teacher on course.teacher_id=teacher.tid where teacher.tname='小多' group by teacher.tid;(2)查询出上过小多老师课的学生ID和该学生上过小多老师的课程数量 select score.student_id,count(score.course_id) from score where score.course_id in (select cid from teacher left join course on teacher.tid=course.teacher_id where teacher.tname='小多') group by score.student_id(3)连表 select student.sid,student.sname from student right join (select B.ID_B as ID_A from (select score.student_id as ID_B,count(score.course_id) as NumB from score where score.course_id in (select cid from teacher left join course on teacher.tid=course.teacher_id where teacher.tname='小多') group by score.student_id) as B left join (select count(course.cid) as NumC from course left join teacher on course.teacher_id=teacher.tid where teacher.tname='小多' group by teacher.tid) as C on B.NumB=C.NumC) as A on student.sid=A.ID_A;
9、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
select student.sid,student.sname from student right join (select B.student_id as ID_A from (select student_id,number from score where course_id=1) as B left join (select student_id,number from score where course_id=2) as C on B.student_id=C.student_id where B.number > C.number) as A on student.sid=A.ID_A;
10、查询有课程成绩小于60分的同学的学号、姓名;
select sid,sname from student where sid in (select student_id from score where number<60);
11、查询没有学全所有课的同学的学号、姓名;
select sid,sname from student where sid not in (select student_id from score group by student_id having count(course_id)=3);
12、查询至少有一门课与学号为“001”的同学所学相同的同学的学号和姓名;
select student.sid,student.sname from student right join (select student_id from score where student_id !=1 and course_id in (select course_id from score where student_id=1) group by student_id) as A on student.sid=A.student_id;
14、查询和“002”号的同学学习的课程完全相同的其他同学学号和姓名;
select student.sid,student.sname from student right join (select student_id,count(course_id) from score where student_id !=2 and course_id in (select course_id from score where student_id=2) group by student_id having count(course_id)=(select count(course_id) from score where student_id=2 group by student_id)) as A on student.sid=A.student_id;
15、删除学习“叶平”老师课的SC表记录;
delete from score where course_id = (select cid from course left join teacher on course.teacher_id=teacher.tid where teacher.tname='叶平');
转载于:https://www.cnblogs.com/yinwenjie/p/10856662.html
Mysql查询语句练习题相关推荐
- MySQL查询语句练习题(面试时可能会遇到哦!)
Sutdent表的定义 字段名 字段描述 数据类型 主键 外键 非空 唯一 自增 Id 学号 INT(10) 是 否 是 是 是 Name 姓名 VARCHAR(20) 否 否 是 否 否 Sex 性 ...
- MySQL查询语句练习题(50题版)
学生表:Student(编号sid,姓名sname,年龄sage,性别ssex) 课程表:Course(课程编号cid,课程名称cname,教师编号tid) 成绩表:Sc(学生编号sid,课程编号ci ...
- mysql 查询姓王_MySQL查询语句练习题,测试足够用了
MySQL查询语句练习题,测试足够用了 博客分类: http://blog.sina.com.cn/s/blog_767d65530101861c.html 1.创建student和score表 CR ...
- mysql查询语句习题._mysql之查询语句练习题
一.连接启动数据库 1.打开phpstudy启动mysql 2.创建数据库 3. 4.测试连接 5.连接 6.导入数据库 二.查询语句练习题 1.查询表里所有的数据 SELECT * FROM Cit ...
- Mysql学习笔记(查询语句练习题1)
表格详情: student表: teacher表: course表: score表: Mysql查询语句练习: 1.查询Student表中的所有记录的Sname.Ssex和Class列 select ...
- mysql 查询语句执行顺序_MySQL 查询语句执行过程
MySQL 查询语句执行过程 Mysql分为server层和存储引擎两部分,或许可以再加一层连接层 连接层(器) Mysql使用的是典型的C/S架构.连接器通过典型的TCP握手完成连接. 需要注的是, ...
- php面试专题---MYSQL查询语句优化
php面试专题---MYSQL查询语句优化 一.总结 一句话总结: mysql的性能优化包罗甚广: 索引优化,查询优化,查询缓存,服务器设置优化,操作系统和硬件优化,应用层面优化(web服务器,缓存) ...
- mysql 查询语句_MySQL相关(一)- 一条查询语句是如何执行的
前言 学习一个新知识最好的方式就是上官网,所以我先把官网贴出来 MySQL官网 (点击查阅),如果大家有想了解我没有说到的东西可以直接上官网看哈~目前 MySQL 最新大版本为8.0,但是鉴于目前应用 ...
- mysql查询语句详解_基于mysql查询语句的使用详解
1> 查询数据表除了前三条以外的数据. 起初我想到的是这条语句 SELECT * FROM admin WHERE userid NOT IN (SELECT userid FROM admin ...
最新文章
- android 白天和夜间模式切换时闪屏问题处理方法
- 《数据安全管理办法(征求意见稿)》发布 为个人数据安全加把锁
- feign调用多个服务_Spring Cloud多个微服务之间调用代码实例
- 手机怎么下载python并安装-Python入门【1】Python下载安装,这几步你要了解
- 兆凯综合布线系统简介
- h3csnmp管理命令_H3C S5500V2-EI系列以太网交换机 命令参考-Release 1118-6W100_网络管理和监控命令参考_SNMP命令-新华三集团-H3C...
- 云智能遥控开关设备再物联网领域的应用:智能养殖高效、生态、安全!
- 【应用篇】WCF学习笔记(一):Host、Client、MetadataExchage
- Bootstrap3 插件的选项
- 对话彭军、楼教主:1.12亿美元融资来了,Pony.ai车队也已在路上 | 变局者
- 【WPF】添加自定义字体
- js/jQuery中的宽高
- EM 算法的推导和解释
- 五笔难拆字拆分方法汇总及详解
- Android N开发 你需要知道的一切
- 三星Galaxy S20:将侧面按钮更改为电源按钮
- Hive通过-f调用sql文件并进行传参
- 【游戏逆向】FPS游戏自瞄透视之堆栈分析
- Web开发中软件工程艺术(Web程序员请进来谈谈,特别是有大型门户网站后台开发的程序员)
- 计算机专业u盘买什么,制作u盘系统选什么模式呢?