10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

select sno,cno from score where degree  in(select max(degree) from score)

11、查询每门课的平均成绩。

select cno,avg(degree) from score group by cno

12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数

select avg(degree) from score where cno like'3%'and cno in(select  cno from score group by cno having count(*)>4)

14、查询所有学生的Sname、Cno和Degree列。

select score.cno,score.degree,student.sname from score,student where student.sno=score.sno

16、查询所有学生的Sname、Cname和Degree列。

select student.sname,course.cname,score.degree from score,course,student where student.sno=score.sno and course.cno=score.cno

17、 查询“95033”班学生的平均分。

select avg(degree) from score where sno in (select sno from student where class='95033')

18、假设使用如下命令建立了一个grade表:

create table grade(low  int(3),upp  int(3),rank  char(1))

insert into grade values(90,100,’A’)

insert into grade values(80,89,’B’)

insert into grade values(70,79,’C’)

insert into grade values(60,69,’D’)

insert into grade values(0,59,’E’)

现查询所有同学的Sno、Cno和rank列。

1.select sno,cno, rank from score  join grade on degree between low and upp

2.select sno,cno,rank from score,grade where degree between low and upp

19、  查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。

1.Select * from score where cno=’3-105’ and degree>(select degree from score where sno=’109’)

查询选修“3-105”课程的并且成绩高于“109”号同学成绩的所有同学的记录。

select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105' )

20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。

select * from score where sno in(select sno from score group by sno having count(*)>1 ) and  degree not in(select max(degree) from score)

21、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。

select * from score where degree>(select degree from score where sno='109' and cno='3-105' )

22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。

select sno,sname,sbirthday from student where YEAR(sbirthday)=(select YEAR(sbirthday) from student where sno=’108’)

23、查询“张旭“教师任课的学生成绩。

select * from score  where cno in(select cno from course where tno=(select tno from teacher where tname='张旭'))

24、查询选修某课程的同学人数多于5人的教师姓名。

select tname from teacher where tno=(select tno from course  where cno=(select cno from score group by cno having count(*)>5))

、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。

select tname,prof from teacher where prof not in(select prof from teacher where depart=’计算机系’and prof in(select prof from teacher where depart=’电子工程系’))

29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。

select * from Score where Cno='3-105' and Degree>any(select Degree from Score where Cno =’3-245') order by Degree desc

30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.

select * from Score where Cno='3-105' and Degree>all(select Degree from Score where Cno ='3-245')

33、 查询成绩比该课程平均成绩低的同学的成绩表。

select * from score a where degree<(select avg(degree) from score b where b.cno=a.cno)

34、查询所有任课教师的Tname和Depart.

select tname,depart from teacher where tno in(select tno from course where cno in(select cno from score))

35 、查询所有未讲课的教师的Tname和Depart.

select tname,depart from teacher where tno in(select tno from course where cno not in(select cno from score))

37、查询Student表中不姓“王”的同学记录。

select * from student where sname not like '王%'

38、查询Student表中每个学生的姓名和年龄。

select sname,year(now())-year(sbirthday) from student

41、查询“男”教师及其所上的课程

select tname,cname from teacher,course where teacher.tno=course.tno and tsex='男'

42、查询最高分同学的Sno、Cno和Degree列。

select sno,cno,degree  from score where degree=(select max(degree) from score)

43、查询和“李军”同性别的所有同学的Sname.

select sname from student where  ssex in(select ssex from student where sname='李军')

44、查询和“李军”同性别并同班的同学Sname.

select Sname from Student where Ssex = (select Ssex from Student where Sname='李军') and class in(select class from student where sname='李军')

45、查询所有选修“计算机导论”课程的“男”同学的成绩表。

select * from score where cno in(select cno from course where cname='计算机导论') and sno in(select sno from student where ssex='男')

mysql select 练习题的更多相关文章

  1. MySQL SELECT练习题*28

    -- (1)用子查询查询员工“张小娟”所做的订单信息. SELECT * FROM order_master WHERE saler_no = ( SELECT employee_no FROM em ...

  2. 【Python全栈-后端开发】MySQL数据库-练习题

    MySQL数据库-练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号 ...

  3. mysql 及练习题

    if() 函数的用法 IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false, mysql,'女','男') as sex fr ...

  4. MYSQL经典练习题,熟悉DQL

    MYSQL经典练习题 (本练习题可让你熟悉DQL,快速的上手DQL) 首先,先在数据库中建立基本数据库以及表项: DROP DATABASE IF EXISTS `test`; CREATE DATA ...

  5. mysql select日期格式

    mysql表中datatime类型存储为2016-01-10,C#直接select 后,在datatable里面看,变成01/10/2016,需要还原回去,使用select DATE_FORMAT(列 ...

  6. mysql select

    select 查询: 赋值:赋值不能应用在where中,因为where操作的是磁盘上的文件,可以应用在having筛选中. 例:select (market_price-shop_price) as ...

  7. mysql select 格式化输出

    select * from test\G; MySQL的客户端命令行工具,有很多方便使用者的特性,某些方面甚至可以说比Oracle的sqlplus更加人性化.当然从整体来说,还是sqlplus更加方便 ...

  8. mysql SELECT FOR UPDATE语句使用示例

    以MySQL 的InnoDB 为例,预设的Tansaction isolation level 为REPEATABLE READ,在SELECT 的读取锁定主要分为两种方式:SELECT ... LO ...

  9. MySQL select into 和 SQL select into

    现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去,虽然可以用以下语句进行复制,总觉得不爽,希望各位帮助下我,谢谢.  answer 01: create table d ...

随机推荐

  1. zookeeper理论

    第一章 Zookeeper server 1.1  Zookeeper基本原理 1.1.1    Zookeeper的保证 l         顺序性,client的updates请求都会根据它发出的 ...

  2. 开始写github

    公司即将开发手机钱庄网,于是最近在写一些手机上常用的js组件做前期准备. 之所以没有沿用pc的那些插件,原因是: 之前的插件大多数是使用jquery写的 移动端的性能要求更严格 以前写的插件从现在看看 ...

  3. SparkStreaming+Flume出现ERROR ReceiverTracker: Deregistered receiver for stream 0: Error starting receiver 0 - org.jboss.netty.channel.ChannelException

    文章发自http://www.cnblogs.com/hark0623/p/4204104.html ,转载请注明 我发现太多太多的坑要趟了… 向yarn提交sparkstreaming了,提交脚本如 ...

  4. vim 全局替换命令

    语法  :[addr]s/源字符串/目的字符串/[option]                     :%s/源字符串/目的字符串/c 全局替换命令为: :%s/源字符串/目的字符串/g [add ...

  5. Spring的replace-method标签

    Spring的解析源码 public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { ...

  6. MVC ViewEngineResult实际上是一种设计

    概述 MVC中, IView代表一个视图,最后是要表现为HTML或者其他的HttpResponse的应答流的: IViewEngine提供了类似工厂的作用或者提供器的作用,以返回一个视图. OO的视觉 ...

  7. LightOJ 1422 (区间DP)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27130 题目大意:按顺序去参加舞会.每个舞会对衣服都有要求.可以 ...

  8. COJ883 工艺品

    试题描述 LZJ和XJR是一对好朋友. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方块放到最右边. 他们想,在仅这一个操作下,最漂 ...

  9. Video Codecs by FOURCC 视频格式编码

    FOURCC Name Summary 1978 A.M.Paredes predictor This is a LossLess video codec. >>> 2VUY 2VU ...

  10. MLUtils.loadLibSVMFile

    import org.apache.spark.mllib.util.MLUtils// Load and parse the data file. val data = MLUtils.loadLi ...