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的表 ...
随机推荐
- C语言字符串与数字相互转换
在C/C++语言中没有专门的字符串变量,通常用字符数组来存放字符串.字符串是以“\0”作为结束符.C/C++提供了丰富的字符串处理函数,下面列出了几个最常用的函数. ● 字符串输出函数puts. ● ...
- We Know What @You #Tag: Does the Dual Role Affect Hashtag Adoption-20160520
分析类的论文 1.Information publication:www2012 author: Mei qiao zhu 2.What 微博中的hashtag既可以表示谈论的内容,又可以代表一个群体 ...
- Android AlertDialog
在Android 4.2 中不推荐使用showDialog弹窗,这里简单总结一下AlertDialog的使用方法,以后复习的时候看着方便,详细使用方法需要的时候再研究. setTitle :为对话框设 ...
- Error: [ng:areq]
错误描述:Error: [ng:areq] http://errors.angularjs.org/1.4.8/ng/areq?p0=HelloCtrl&p1=not%20a%20functi ...
- Android核心机制
Android开篇 图解Android - Zygote, System Server 启动分析 图解Android - Binder 和 Service 图解Android - System Ser ...
- 全面理解Context
出处:http://blog.csdn.net/lmj623565791/article/details/40481055,本文出自:[张鸿洋的博客] 本文大多数内容翻译自:http://www.do ...
- 如何更新firefox中的flash
要了解当前安装的版本是否为最新版本,请访问 插件检查页面http://www.mozilla.com/plugincheck/ ,如果该页面告诉你 Flash 插件需要更新,请手动安装最新版本. 使 ...
- 【POJ 2942】Knights of the Round Table(点双连通分量,二分图染色)
圆桌会议必须满足:奇数个人参与,相邻的不能是敌人(敌人关系是无向边). 求无论如何都不能参加会议的骑士个数.只需求哪些骑士是可以参加的. 我们求原图的补图:只要不是敌人的两个人就连边. 在补图的一个奇 ...
- 【UVALive 4642】Malfatti Circles(圆,二分)
题 给定三角形,求三个两两相切且与三角形的一条边相切的圆的半径. 二分一个半径,可以得出另外两个半径,需要推一推公式(太久了,我忘记了) #include<cstdio> #include ...
- 【poj2942】 Knights of the Round Table
http://poj.org/problem?id=2942 (题目链接) 题意 有n个骑士要去参加圆桌会议,他们将围成一圈,想要他们不打架,当且仅当参加圆桌会议的骑士数为奇数并且相邻的两个骑士不互相 ...