mysql练习题练习
1、数据库是按照原文制作的,表格结构一样具体存储的数据有些差异
原文地址:MySQL练习题
原答案地址:MySQL练习题参考答案
2、查询“生物”课程比“物理”课程成绩高的所有学生的学号;
select wl.sid from (select sc.student_id as sid,sc.number as grade from score sc,course c
where c.cid=sc.course_id and c.cname='物理') as wl,(select sc.student_id as sid,sc.number as
grade from score sc,course c where c.cid=sc.course_id and c.cname='生物') as sw where
wl.sid=sw.sid and sw.grade>wl.grade;
3、查询平均成绩大于60分的同学的学号和平均成绩;
select student_id,avg(number) as avg from score group by student_id having avg(number)>60;
4、查询所有同学的学号、姓名、选课数、总成绩;
select s.sid,s.sname,w.total,w.sum from student s,(select student_id,count(course_id) as
total,sum(number) as sum from score group by student_id) as w where s.sid=w.student_id;
5、查询姓“李”的老师的个数;
select count(*) from teacher where tname like '钱%';
6、查询没学过“叶平”老师课的同学的学号、姓名;
select s.sid,s.sname from student as s where s.sid not in (select distinct sc.student_id from
score as sc,teacher as t,course as c where t.tid=c.teacher_id and c.cid=sc.course_id and
t.tname='赵');
7、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
select student.sid,student.sname from student,(select * from score where course_id=1) as w,
(select * from score where course_id=2) as e where w.student_id=e.student_id and
student.sid=w.student_id;
8、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
select s.sid,s.sname from student as s where s.sid in (select distinct sc.student_id from
score as sc,teacher as t,course as c where t.tid=c.teacher_id and c.cid=sc.course_id and
t.tname='赵');
9、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
select student.sid as id,student.sname as name from student,(select w.student_id as wid from
(select * from score where course_id=1) as w,(select * from score where course_id=2) as e
where w.student_id=e.student_id and w.number>e.number) as m where m.wid=student.sid;
10、查询有课程成绩小于60分的同学的学号、姓名;
select s.sid as id,s.sname as name from student as s,score as sc where s.sid=sc.student_id
and sc.number<60 group by s.sid;
11、查询没有学全所有课的同学的学号、姓名;
select sid,sname from student where sid in (select distinct student_id from score group by
student_id having count(course_id)=(select count(*) from course));
12、查询至少有一门课与学号为“001”的同学所学相同的同学的学号和姓名;
select sid,sname from (select distinct student_id from score left join (select course_id from
score left join student on score.student_id = student.sid where student.sid=1) as c on
score.course_id = c.course_id where student_id != 1) s left join student on
s.student_id=student.sid;
13、查询至少学过学号为“001”同学所有一门课的其他同学学号和姓名;
select student.sid,student.sname from student right join score on
student.sid=score.student_id where student_id!=1 and course_id in (select course_id from
score where student_id=1) group by student_id having count(course_id)=(select count
(course_id) from score where student_id=1);
14、查询和“002”号的同学学习的课程完全相同的其他同学学号和姓名;
select sid,sname from student where sid in (select student_id from score right join (select
course_id from score where student_id=1) w on score.course_id=w.course_id where student_id!=1
group by student_id having count(student_id)=(select count(*) from score where
student_id=1));
15、删除学习“叶平”老师课的SC表记录;
delete from score where course_id in (select cid from teacher,course where
teacher.tid=course.teacher_id and teacher.tname='周');
16、向SC表中插入一些记录,这些记录要求符合以下条件:①没有上过编号“002”课程的同学学号;②插入“002”号课程的平均成绩;
insert into score(student_id,course_id,number) select sid,1,(select avg(number) from score
where course_id=1) from student where sid not in (select student_id from score where
course_id=1);
未完待续
mysql练习题练习的更多相关文章
- MySQL练习题
MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号和平均成 ...
- MySQL练习题参考答案
MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...
- s15day12作业:MySQL练习题参考答案
MySQL练习题参考答案 导出现有数据库数据: mysqldump -u用户名 -p密码 数据库名称 >导出文件路径 # 结构+数据 mysqldump -u用户名 -p ...
- Python/ MySQL练习题(一)
Python/ MySQL练习题(一) 查询“生物”课程比“物理”课程成绩高的所有学生的学号 SELECT * FROM ( SELECT * FROM course LEFT JOIN score ...
- python/MySQL练习题(二)
python/MySQL练习题(二) 查询各科成绩前三名的记录:(不考虑成绩并列情况) select score.sid,score.course_id,score.num,T.first_num,T ...
- python 全栈开发,Day65(MySQL练习题,参考答案)
一.MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号.ps:针对的是自己的生物成绩比物理成绩高,再 ...
- mysql 练习题答案
一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名和平均成绩 5.查询所有学生的 ...
- MySQL练习题及答案(复习)
新建一个叫做 review 的数据库,将测试数据脚本导进去.(可以使用Navicat查询功能) /* Navicat MySQL Data Transfer Source Server : DB So ...
- mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风
(-1)写在前面 文章参考http://blog.sina.com.cn/willcaty. 针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答. (0) 基础数据 student表 +-- ...
随机推荐
- instancetype和id的区别,objective-c
instancetype clang 3.5 提供的关键字, 表示:某方法返回未知类型的OC对象 都知道id任意类型关键字,为什么还会出现一个新的关键字? 返回关联类型 1.类方法中,alloc ...
- webapplication发布
在vs2010里写的 ASP.NET Web Application 发布步骤: ①:右击Web Application项目可以看到发布,弹出的对话框里选择要发布的路径,路径选择一个容易记住的地址即可 ...
- Markdown引用图片,且不使用网上链接的解决方法
首先介绍下markdown使用图片的3种方法 使用本地图片,缺点是要用到本地的绝对路径,不适合对文档做迁移,否则会有图片链接失效的情况 的时候没办法做到将首字母转换成小写.日期再序列化过后是时间戳需要到前台重新处理或者提在在 ...
- 腾讯云服务器CVM购买详细过程 选择我们需要的腾讯云服务器
腾讯云服务商有云服务器.云数据库.CDN.云存储等产品,其中较多的用户会选择腾讯云服务器,因为用途比较广泛,比如用来软件的运行以及网站建设,如今一般都是用云服务器,而不是用虚拟主机,毕竟虚拟主机的性价 ...
- COGS 2769. mk去撸串
[题目描述] 今天 mk 去撸串 ,恰逢店里活动 ,如果吃一种串串超过记录, 可以 赠送 328, 所以 mk 想知道他吃的串串中吃的最多的种类是什么. [输入格式] 第一行一个整数 1<=n& ...
- 那些年,被我蠢哭了的php代码小错误~~~
首先,我爱敲代码!!!而且我很喜欢修改bug,在看到那些bug的时候,我是兴奋的,毕竟当你解决这个bug之后感觉是很爽的. 在学习的过程中,看到无数的bug,有一些错误是很微小的,一般在PHP中都能通 ...
- 更新KB915597补丁后导致“您的windows副本不是正版”的解决方案
更新KB915597补丁后导致“您的windows副本不是正版”的解决方案 解决方法: 运行cw.exe(https://pan.lanzou.com/i05ya8h),直至提示成功: 重新启动操作系 ...
- java Vamei快速教程01
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Java是完全面向对象的语言.Java通过虚拟机的运行机制,实现“跨平台”的理念. ...
- Android(java)学习笔记75:ListViewProject案例(ListView + BaseAdapter + CheckBox)
这个案例可能稍微复杂一点,我会讲述详细一点: 1. 首先是AndroidManifest.xml: <?xml version="1.0" encoding="ut ...