Orcle数据库查询练习复习:三
一、题目
1.与“张三”同乡的男生姓名
select * from student where snativeplace=(select snativeplace from student where sname='张三') and ssex='男'
2.选修了赵露老师所讲课程的学生人数
select count(*) from mark where cid in(select cid from course where tid=(select tid from teacher where tname='赵露')) group by cid
select count(distinct sid) from mark where cid in(select cid from course where tid=(select tid from teacher where tname='赵露'))
3.查询没学过“王”姓老师课的同学的学号、姓名
select * from student where sid not in(select sid from mark where cid in(
select cid from course where tid in(select tid from teacher where tname like '王%')))
4.数学”课程得最高分的学生姓名、性别
select * from student where sid in(
select sid from mark where cid=(
select cid from course where cname='数学')
and cmark>= all(
select cmark from mark where cid=(select cid from course where cname='数学')
))
5.统计每门课程的平均成绩,并按照成绩降序排序
select *from(select (select cname from course where cid=m.cid), avg(cmark) cavg
from mark m group by cid )order by cavg desc
select * from (select avg(cmark) cavr from mark group by cid)order by cavg desc
6.子查询实现查询‘3-2班’"张立"同学的"英语"成绩
select cmark 成绩 from mark where sid=(
select sid from student where sname='张三'and sclass='2班')
and cid =(select cid from course where cname='英语')
7.查询所在班级和该班内学生的年龄之和,对该班级中每个人的年龄进行比对,(要求大于20岁的人参与统计)
select sclass ,sum(sage) from student where sage>=20 group by sclass
8.查询所在班级和该班内学生的年龄之和,(要求该班级中每个人的年龄都大于20岁)
select sclass ,sum(sage) from student group by sclass having min(sage)>20 select sclass ,sum(sage) from student where sclass not in(
select sclass from student where sage<20 group by sclass) group by sclass
9.用子查询实现查询选修“高等数学”课的全部学生的高等数学总成绩
select sum(cmark) from mark where cid =(select cid from course where cname='数学')
10.用子查询实现查询选修“高等数学”课的全部学生的所有课程总成绩*/
select sum(cmark) from mark where sid in(select sid from mark where cid =(select cid from course where cname='数学'))
11.请用两种方法实现:查找所有成绩都在68分以上的学生姓名*/
select sid,sname from student where sid in (
select sid from mark group by sid having min(cmark)>=68) select sid,sname from student s where exists (
select sid from mark m where s.sid=m.sid group by sid having min(cmark)>=68)
12.查找至少2门成绩在80分以上的学生姓名
select sname from student where sid in(
select sid from mark where cmark >=80 group by sid having count(*)>=2
)
13.查询至少有一门课与张三同学所学相同的同学的学号和姓名
select sid,sname from student where sid in(
select sid from mark where cid in (
select cid from mark where sid in (
select sid from student where sname='张三')))
14.没有选修“数学”课的学生的姓名*/
select sname from student where sid in (
select sid from mark where sid not in(
select sid from mark where cid in(
select cid from course where cname='数学'
)
)
)
15.查询个人总成绩小于平均总成绩的学生姓名
step1、计算出平均总分
step1.1计算出个人总分表
select sid,sum(cmark) smk from mark group by sid
step1.2对总分表求平均值
select avg(smk) from (step1.1)
step2、找出在个人总分表中找出谁的总分低于step1
step2.1 select sid from (step1.1)where smk <(step1.2)
step2.2 select sname from student where sid in (step2.1)
Orcle数据库查询练习复习:三的更多相关文章
- Orcle数据库查询练习复习:一
一.创建数据库和表 drop table student; create table student ( sid int, sname ), sage int, ssex ), snativeplac ...
- Orcle数据库查询练习复习:四
一.题目 1.找出张三的最高分和最低分以及对应的课程名 select * from course c,mark m where c.cid=m.cid and sid =(select sid fro ...
- Orcle数据库查询练习复习:二
一.题目 1.找出所有成绩均低于80的学生姓名 select sname from student where sid in( ) select sname from student where si ...
- Yii2.0数据库查询实例(三)
常用查询: // WHERE admin_id >= 10 LIMIT 0,10 User::find()->])->offset()->limit()->all() / ...
- SQL复习三(子查询)
子查询 子查询就是嵌套查询,即select中包含这select,如果一条语句中存在着两个,或者两个以上的select,那么就是子查询语句了. 子查询出现的位置 where后,作为条件的一部分: fro ...
- MariaDB使用数据库查询《三》
MariaDB使用数据库查询 案例5:使用数据库查询 5.1 问题 本例要求配 ...
- 第九十九天上课 PHP TP框架 数据库查询和增加
在Model文件夹下创建模型,文件命名规则 : 表名Model.class.php <?php namespace Home\Model; use Think\Model; class yong ...
- 【转】Delphi多线程学习(9):多线程数据库查询(ADO)
原文:http://www.cnblogs.com/djcsch2001/articles/2382559.html ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用 ...
- 教程-Delphi多线程数据库查询(ADO)
ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...
随机推荐
- smarty安装及例子
环境: smarty3.1.16 1.在http://www.smarty.net/download下载最新smarty包,window选择zips,linux下选择tar.gz.以windows为例 ...
- iOS点击cell查看大图,点击大图还原小图-b
一.项目需求 用collectionView展示很多照片,点击某个照片,用全屏scrollView无限循环的方式查看图片.点击放大的图片,图片缩小到原先的尺寸. 如图gif1.gif所示,点击中间的图 ...
- SVN的405错误
错误1: 如果你没有阅读以下文字,活该你倒霉(这段文字是在googlecode添加新项目时生成的): Command-line access If you plan to make changes, ...
- 贱贱的美团安卓客户端---如何实现让安卓app在应用列表获得较靠前的位置
起因: 自打愚安我开始使用android设备以来,一直觉得google还算厚道,应用列表里的顺序一直都是依据APP的名称,按照先中文(拼音字母表顺序),后英文(字母表顺序)的原则进行排序的,并没有说G ...
- java集合类(四)About Set
接上篇:java集合类(三)About Iterator & Vector(Stack) 之前,在比较java常见集合类的时候,就了解到一点有关Set的特性.实现类及其要求等,读者可以去温习下 ...
- 使用Putty连接VirtualBox的Ubuntu
从vbox中安装了ubuntu server,然后用ssh连过去,发现有一个错误:server unexpectedly closed network connection.猛然发现,ssh没有安装. ...
- Codeforces Round #256 (Div. 2) Multiplication Table
C题, #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5005 using ...
- hdu 1754 线段树入门
线段树点修改 区间最大值查询 #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- 解决unity3d发布的网页游戏放到服务器上无法使用的问题
http://www.unity蛮牛.com/blog-2429-1226.html 第一次把unity3d发布的网页游戏放到服务器上(Win2003),发现无法使用.可以尝试以下办法. ...
- Lua 简单的IO交互 和迷宫代码
function room1 () print("in room1") local move = io.read() if move == "south" th ...