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的表 ...
随机推荐
- java swing模仿随机频谱
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Grap ...
- Windows10一周年庆典壁纸
example: 下载:http://pan.baidu.com/s/1b55D5k
- js 基础(一)
<!--最近需要用到js相关的知识 就把在W3cSchool 下学到的东西做个笔记,方便以后再看 --><!DOCTYPE html> <html> <hea ...
- Beta项目冲刺 --第五天
忙里偷得半日闲-- 队伍:F4 成员:031302301 毕容甲 031302302 蔡逸轩 031302430 肖阳 031302418 黄彦宁 会议内容: 1.站立式会议照片: 2.项目燃尽图 3 ...
- ORA-600(qerltcInsertSelectRop_bad_state)错误
来源于: http://blog.itpub.net/22458783/viewspace-615501/ 这是碰到的第一个11.2上的bug,在利用IGNORE_ROW_ON_DUPKEY_INDE ...
- “Ceph浅析”系列之七——关于Ceph的若干想法
本篇文章的内容,主要是笔者在调研分析Ceph过程中产生的一些思考.因为其中的内容比较自由发散,且大多是笔者的个人见解,故此另启一文进行讨论. 关于Ceph的性能 目前为止,本系列的文章中没有涉及到Ce ...
- SharedPrefernces使用实例讲解
activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- linux系统下who&who am i与whoami的区别,以及与select * from dba_users的区别
who am i :表示登录此虚拟机(或者计算机)时,使用的操作系统级别用户名称 whoami:表示当前正在使用的操作系统级别用户名称 select username from dba_users;查 ...
- url中#号的作用
url中#号的作用就是本页面位置跳转 比如这个url地址:http://www.aaaaa.com/index.html?ad=34&m=c#red red就是index.html页面的依哥位 ...
- HTTP协议学习---(六)缓存
本文介绍浏览器和Web服务器之间如何处理"浏览器缓存",以及控制缓存的http header. 本文会使用Fiddler来查看HTTP request和Response, 如果不熟 ...