MYSQL select查询练习题
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查询练习题的更多相关文章
- day41:MYSQL:select查询练习题
目录 1.表结构 2.创建表和插入数据 3.习题 1.表结构 2.建表和插入数据 # 创建班级表 create table class( cid int primary key auto_increm ...
- MySQL Select查询
1. 基本语法: SELECT {* | <字段列名>} [ FROM <表 1>, <表 2>… [WHERE <表达式> [GROUP BY < ...
- mysql常见查询练习题
#建学生信息表student create table student ( sno varchar(20) not null primary key, sname varchar(20) not nu ...
- MySQL select 查询之分组和过滤
SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...
- MySQL select 查询的分页和排序
SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...
- mysql select语句查询流程是怎么样的
select查询流程是怎么样的 mysql select查询的数据是查询内存里面,如果没有查询的数据没有在内存,就需要mysql的innodb引擎读取磁盘,将数据加载的内存后在读取.这就体现了,mys ...
- mysql DML select查询
windows上的操作 1.从官网下载mysql 下载navicat,用来连接mysql的 2.打开运行启动mysql 3.在navicat上的连接打开新建连接 然后输入链接名,连接名就是用户名,自己 ...
- MySQL连表查询练习题
1.建库 库名:linux50 字符集:utf8 校验规则:utf8_general_ci  create database linux4 charset utf8 default collate ...
- MySQL 表查询语句练习题
MySQL 表查询语句练习题: 一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表 ...
随机推荐
- Matlab生成M序列的伪随机码
伪随机编码中较常用的是m序列,它是线性反馈移位寄存器序列的一种,其特点是在相同寄存器级数的情况下输出序列周期最长.线性反馈移位寄存器的工作原理是,给定所有寄存器一个初始值,当移位脉冲到来时,将最后一级 ...
- 品牌OEM信息导入工具(实测支持Win10)
OEM修改,定制专属LOGO. 免费下载:http://yunpan.cn/cmZuTYWLIGX6Q 访问密码 2da7 备用通道: http://pan.baidu.com ...
- Bete冲刺第二阶段
Bete冲刺第二阶段 今日工作: web: 修复了a版本中接口数据返回错误的问题.通知对数据表新增了几个字段.并且新增了一个通知查询的接口. ios: 修正网络连接bug 招募功能界面完成但是跳转问题 ...
- 使用while循环输入 1 2 3 4 5 6 8 9 10
n = 1 while n<11: if n==7: pass else: print(n) n = n +1
- HTML 5 video 标签跨浏览器兼容
<video width="320" height="240" controls> <source src="movie.mp4 ...
- nginx实战2---浏览器设置缓存
对常见格式的图片文件等在浏览器本地缓存,对于css,js等文件在浏览器本地缓存. 语法:expires [time|epoch|max|off 默认值:off expires指令控制HTTP应答中的& ...
- ES6新特性:Javascript中Generator(生成器)
ES6的很多特性都跟Generator扯上关系,而且实际用处比较广, 包含了任何需要异步的模块, 比如ajax, filesystem, 或者数组对象遍历等都可以用到: Generator的使用: G ...
- git初体验(七)多账户的使用
多github帐号的SSH key切换 我有两个github帐号,一个是个人所用,一个是为公司项目所用.如果是单用户(single-user),很方便,默认拿id_rsa与你的github服务器的公钥 ...
- Android GUI系统
图解Android - Android GUI 系统 (1) - 概论 图解Android - Android GUI 系统 (2) - 窗口管理系统 图解Android - Android GUI ...
- 浅谈malloc()与free()
malloc()与free() l 函数原型 malloc函数的函数原型为:void* malloc(unsigned int size),它根据参数指定的尺寸来分配内存块,并且返回一个void型指 ...