10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
 select sno,cno from score where degree=(select max(degree) from score)
 select * from score order by degree desc limit 0,1

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)
 select avg(degree) from score group by cno having count(*)>4 and cno like '3%'

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列。
 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 max(degree) from score where sno='109')
 (2)select * from score where cno = '3-105' and degree>(select max(degree) from score where sno='109' and cno='3-105')

20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
 (1)select * from score where sno in(select sno from score group by sno having count(*)>1) and degree<(select max (degree) from score)

(2)select * from score a where sno in(select sno from score group by sno having count(*)>1) and degree<(select max (degree) from score b where b.cno = a.cno)

28、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
 select tname,prof from teacher where depart='计算机系'  and prof not in(select prof from teacher where depart='电子工程系')
union
select tname,prof from teacher where depart='电子工程系'  and prof not in(select prof from teacher where depart='计算机系')

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

select tname,prof from teacher a where prof not in(select prof from teacher b where a.depart!=b.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')
 select * from score where cno='3-105' and degree>(select min(degree) from score where cno='3-245')

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')
 select * from score where cno='3-105' and degree>(select max(degree) from score where cno='3-245')

36、查询至少有2名男生的班号。
 select class from student where ssex='男' group by class having count(*)>1

38、查询Student表中每个学生的姓名和年龄。
 select sname,year(now())-year(sbirthday) from student;
 select sname,(DATE_FORMAT(from_days(to_days(now())-to_days(sbirthday)),'%Y')+0) as age from student;

45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
 select * from score where sno in(select sno from student where ssex='男') and cno in(select cno from course where cname='计算机导论');

select student.sno,student.sname,student.ssex,student.sbirthday,student.class,course.cno,course.cname,score.degree from student,course,score where student.sno in (select sno from student where ssex='男') and course.cno in (select cno from course where cname='计算机导论') and student.sno=score.sno and course.cno=score.cno;

MYSQL select查询练习题的更多相关文章

  1. day41:MYSQL:select查询练习题

    目录 1.表结构 2.创建表和插入数据 3.习题 1.表结构 2.建表和插入数据 # 创建班级表 create table class( cid int primary key auto_increm ...

  2. MySQL Select查询

    1. 基本语法: SELECT {* | <字段列名>} [ FROM <表 1>, <表 2>… [WHERE <表达式> [GROUP BY < ...

  3. mysql常见查询练习题

    #建学生信息表student create table student ( sno varchar(20) not null primary key, sname varchar(20) not nu ...

  4. MySQL select 查询之分组和过滤

    SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...

  5. MySQL select 查询的分页和排序

    SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...

  6. mysql select语句查询流程是怎么样的

    select查询流程是怎么样的 mysql select查询的数据是查询内存里面,如果没有查询的数据没有在内存,就需要mysql的innodb引擎读取磁盘,将数据加载的内存后在读取.这就体现了,mys ...

  7. mysql DML select查询

    windows上的操作 1.从官网下载mysql 下载navicat,用来连接mysql的 2.打开运行启动mysql 3.在navicat上的连接打开新建连接 然后输入链接名,连接名就是用户名,自己 ...

  8. MySQL连表查询练习题

    1.建库 库名:linux50 字符集:utf8 校验规则:utf8_general_ci  create database linux4 charset utf8 default collate ...

  9. MySQL 表查询语句练习题

    MySQL 表查询语句练习题: 一.  设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表 ...

随机推荐

  1. VBPR: Visual Bayesian Personalized Ranking from Implicit Feedback-AAAI2016 -20160422

    1.Information publication:AAAI2016 2.What 基于BPR模型的改进:在商品喜好偏序对的学习中,将商品图片的视觉信息加入进去,冷启动问题. 3.Dataset Am ...

  2. RabbitMQ官方中文入门教程(PHP版) 第四部分:路由(Routing)

    路由(Routing) 在前面的教程中,我们实现了一个简单的日志系统.可以把日志消息广播给多个接收者. 本篇教程中我们打算新增一个功能——使得它能够只订阅消息的一个字集.例如,我们只需要把严重的错误日 ...

  3. python基础-基本数据类型

    一. 运算符 1.算数运算: ps: 示例1: python2.7示例 #!/usr/bin/env python # -*- coding:utf-8 -*- #Author: nulige #算数 ...

  4. dblink连接的目标端 session不断的问题。

    来源于:http://blog.itpub.net/22782896/viewspace-676842/ 1.在使用了dblink的存储过程中,可以显示的手动关闭dblink连接,具体写法如下(测试存 ...

  5. div两栏等高布局

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. 分布式学习材料Distributed System Prerequisite List

    接下的内容按几个大类来列:1. 文件系统a. GFS – The Google File Systemb. HDFS1) The Hadoop Distributed File System2) Th ...

  7. Qt学习中遇到的问题

    问题: 一个Qt小项目,编译成功并成功运行,但应用程序输出中出现如下异常:FTH: (9892): *** Fault tolerant heap shim applied to current pr ...

  8. 在Winform中播放视频等【DotNet,C#】

    在项目中遇到过这样的问题,就是如何在Winform中播放视频.当时考察了几种方式,第一种是直接使用Windows Media Player组件,这种最简单:第二种是利用DirectX直接在窗体或者控件 ...

  9. [转]REST简介

    转自:http://www.cnblogs.com/loveis715/p/4669091.html 一说到REST,我想大家的第一反应就是“啊,就是那种前后台通信方式.”但是在要求详细讲述它所提出的 ...

  10. eclipse-mvn打包跳过junit测试类

    修改pom.xml,在build选项加上plugins的这段如下: <build> ..... <plugins> <plugin> <groupId> ...