一、题目

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数据库查询练习复习:三的更多相关文章

  1. Orcle数据库查询练习复习:一

    一.创建数据库和表 drop table student; create table student ( sid int, sname ), sage int, ssex ), snativeplac ...

  2. Orcle数据库查询练习复习:四

    一.题目 1.找出张三的最高分和最低分以及对应的课程名 select * from course c,mark m where c.cid=m.cid and sid =(select sid fro ...

  3. Orcle数据库查询练习复习:二

    一.题目 1.找出所有成绩均低于80的学生姓名 select sname from student where sid in( ) select sname from student where si ...

  4. Yii2.0数据库查询实例(三)

    常用查询: // WHERE admin_id >= 10 LIMIT 0,10 User::find()->])->offset()->limit()->all() / ...

  5. SQL复习三(子查询)

    子查询 子查询就是嵌套查询,即select中包含这select,如果一条语句中存在着两个,或者两个以上的select,那么就是子查询语句了. 子查询出现的位置 where后,作为条件的一部分: fro ...

  6. MariaDB使用数据库查询《三》

                                                                 MariaDB使用数据库查询 案例5:使用数据库查询 5.1 问题 本例要求配 ...

  7. 第九十九天上课 PHP TP框架 数据库查询和增加

    在Model文件夹下创建模型,文件命名规则 : 表名Model.class.php <?php namespace Home\Model; use Think\Model; class yong ...

  8. 【转】Delphi多线程学习(9):多线程数据库查询(ADO)

    原文:http://www.cnblogs.com/djcsch2001/articles/2382559.html ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用 ...

  9. 教程-Delphi多线程数据库查询(ADO)

    ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...

随机推荐

  1. php数组声明、遍历、数组全局变量使用小结

    数组的本质:管理和操作一组变量,成批处理,下面为大家介绍下数组的分类.数组的分类及使用说明,感兴趣的朋友可以了解下哈   php教程:数组声明,遍历,数组全局变量  <? /* * 一.数组的概 ...

  2. Linux之父访谈录:设计内核只为了好玩

    2010-09-20 10:36 “有 些人生来就具有统率百万人的领袖风范;另一些人则是为写出颠覆世界的软件而生.唯一一个能同时做到这两 者的人,就是Linus Torvalds.”这是美国<时 ...

  3. Django之Model(一)--基础篇

    0.数据库配置 django默认支持sqlite,mysql, oracle,postgresql数据库.Django连接数据库默认编码使用UTF8,使用中文不需要特别设置. sqlite djang ...

  4. 每日一“酷”之copy

    Copy – 复制对象 作用:提供一些函数,可以使用浅副本或深副本语义复制对象. copy模块包括两个函数copy()和deepcopy(),用于复制现有的对象 1.  浅副本 copy()创建的浅副 ...

  5. 1093. Count PAT's (25)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  6. 相同的 birthday

    Description Sometimes some mathematical results are hard to believe. One of the common problems is t ...

  7. 绘制dot 图

    常用参数 格式:dot -T<type> -o<outfile> <infile.dot> 输入文件是<infile.dot>,生成的格式由<ty ...

  8. Vbox安装oracle-linux报错:VT-x features locked or unavailable in M

    1.安装完Vbox后,通过vbox来安装oracle-linux时报“VT-x features locked or unavailable in MSR”: 2.报错原因:CPU没有开启虚拟化支持 ...

  9. mapreduce 实现矩阵乘法

    import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs ...

  10. mtu

    通信术语 最大传输单元(Maximum Transmission Unit,MTU)是指一种通信协议的某一层上面所能通过的最大数据包大小(以字节为单位).最大传输单元这个参数通常与通信接口有关(网络接 ...