mysql查询选修课的人数_mysql查询语句练习
#建学生信息表student
create table student
(
sno varchar(20) not null primary key,
sname varchar(20) not null,
ssex varchar(20) not null,
sbirthday datetime,
class varchar(20)
);
#建立教师表
create table teacher
(
tno varchar(20) not null primary key,
tname varchar(20) not null,
tsex varchar(20) not null,
tbirthday datetime,
prof varchar(20),
depart varchar(20) not null
);
#建立课程表course
create table course
(
cno varchar(20) not null primary key,
cname varchar(20) not null,
tno varchar(20) not null,
foreign key(tno) references teacher(tno)
);
#建立成绩表
create table score
(
sno varchar(20) not null primary key,
foreign key(sno) references student(sno),
cno varchar(20) not null,
foreign key(cno) references course(cno),
degree decimal
);
1、 查询Student表中的所有记录的Sname、Ssex和Class列。
select sname,ssex,class from student
2、查询教师所有的单位即不重复的depart列。
select distinct depart from teacher3、 查询Student表的所有记录。
select * from student4、 查询Score表中成绩在60到80之间的所有记录。
select * from score where degree between 60 and 805、 查询Score表中成绩为85,86或88的记录。
select * from score where degree in(85,86,88)6、 查询Student表中“95031”班或性别为“女”的同学记录。
select * from student where class='95031' or ssex='女'7、 以class降序查询Student表的所有记录。
select * from student order by class desc8、 以cno升序、degree降序查询Score表的所有记录。select * from score order by cno asc,degree desc9、 查询“95031”班的学生人数。select count(*) from student where class='95031'10、查询score表中的最高分的学生学号和课程号
select sno,cno from score where degree=(select max(degree) from score)11、查询每门课的平均成绩。select avg(degree) from score group by cno12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。select avg(degree) from score where cno like '3%' and cno in (select cno from score group by cno having count(*)>513、查询分数大于70,小于90的Sno列。select sno from score where degree>70 and degree<9014、查询所有学生的Sname、Cno和Degree列。select sname,cno,degree from score,student where score.cno=student.sno15、查询“95033”班学生的平均分。
select avg(degree) as 'class=95033' from score where sno in (select sno from student where class='95033')
16、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。select * from score where degree>(select degree from score where sno='109' and cno='3-105'
17、查询“张旭“教师任课的学生成绩。
select sno,degree from score,course where score.cno=course.cno and course.tno=(select tno from teacher where tname='张旭'18、查询选修某课程的同学人数多于5人的教师姓名。select tname from teacher where tno=(select tno from course where cno=(select cno from score group by cno having count(*)>5))19、查询95033班和95031班全体学生的记录。select * from student where class in ('95031','95033')20、查询存在有85分以上成绩的课程Cno.
select cno from score where degree>8521、查询出“计算机系“教师所教课程的成绩表。
select * from course where cno in (select cno from course where tno in(select tno from teacher where depart='计算机系'))22、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
select cno,sno,degree from score where cno='3-105' and degree> any(select degree from score where cno='3-245') order by degree desc23、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degreeselect cno,sno,degree from score where cno='3-105' and degree> aall(select degree from score where cno='3-245') order by degree desc24、查询成绩比该课程平均成绩低的同学的成绩表。
select * from score as a where degree
select tname,depart from teacher where tno in (select tno from course)26 、 查询所有未讲课的教师的Tname和Depart.
select tname,depart from teacher where tno not in (select tno from course where cno in (select cno from course))27、查询至少有2名男生的班号。
select class from student where ssex='男' group by class having count(*)>128、查询Student表中不姓“王”的同学记录。
select * from student where sname not like '王%’29、查询Student表中最大和最小的Sbirthday日期值。
select max(sbirthday),min(sbirthday) from student30、查询所有选修“计算机导论”课程的“男”同学的成绩表。select sno,cno,degree from score where cno=(select cno from course where cname='计算机导论') and sno in (select sno from student where ssex='男')31、查询和“李军”同性别并同班的同学Sname.
select sname from student where ssex=(select ssex from student where sname='李军') and class=(select class from student where sname='李军')
mysql查询选修课的人数_mysql查询语句练习相关推荐
- mysql查询95031班人数_MySQL查询练习
个人笔记 仅供参考 查询练习数据准备 准备一些数据供下文使用 1.学生表(student) 学号,姓名,性别,出生年月日,班级 mysql> create table student( -> ...
- mysql语句 查询前5个_MySQL 查询语句--------------进阶5:分组查询
#进阶5:分组查询 /* select 分组函数,列(要求出现在group by的后面) from 表 [where 筛选条件] group by 分组的列表 [order by 子句] 注意: 查询 ...
- mysql查询95031班人数_MySQL的查询练习 - osc_1ngzqx2h的个人空间 - OSCHINA - 中文开源技术交流社区...
student表 teacher表 course表 score表 对这四个表进行一些练习. 1:查询student表中所有记录. select *from student; 2:查询student表中 ...
- mysql中嵌套查询分数大于70分的人数_MySQL查询练习题,自我解答版本
#1.查询"01"课程比"02"课程成绩高的学生的信息及课程分数 SELECT c.*,a.s_score,b.s_score FROM score AS a, ...
- MySQL查询自己的学号_Mysql 查询练习
Mysql 查询练习 ---创建班级表 create tableclass( cidint auto_increment primary key, captionvarchar(20) )engine ...
- mysql怎么查询借阅相同图书_MySQL查询练习2
MySQL查询练习2 导读: 本次MySQL的查询语句是本人考试题目: 所有题目都已通过: 该查询练习并没有sql文件进行检查: 如果有书写以及其他错误欢迎指出. 题目正文: 1.找出借书超过5本的借 ...
- mysql查询男生基本情况_MYSQL查询操作 详细
学习目标 1 掌握select查询所有字段.指定字段的数据 2 掌握消除重复行命令distinct 3 掌握as给字段.表起别名 4 掌握条件查询where后跟比较运算符.逻辑运算符的用法 5 掌握条 ...
- mysql是否有缓存区_Mysql查询高速缓存区
为了提高查询速度,Mysql会维护一个内存区域(官方文档指出,大小至少41984B)对查询结果进行缓存,当查询时发现缓存区里有数据则直接返回结果而不用去执行sql语句. 查询命中的条件 每个缓存查询至 ...
- 查询mysql 中的空文本_MySQL查询以显示空列的自定义文本
让我们首先创建一个表-mysql> create table DemoTable -> ( -> FirstName varchar(20) -> ); 使用插入命令在表中插入 ...
最新文章
- 康泰瑞影推高性能3D/4D超声可视化方案
- pxe+kickstart无人值守安装
- 支付产品必懂的会计基础及如何应用
- 机器学习——相似度算法汇总
- 云服务器(Centos)部署SVN
- 自定义泛型集合,接口
- mongoDB 3.0以前版本 - 入门指南、示例
- 理解Iass Pass SasS三种云服务区别
- PhotoShop简单案例(4)——利用ps制作正在加载中动画(loading.gif)
- 【re】python正则表达式的用法汇总 + 使用正则表达式提取不让复制的网页的文本内容!
- 【风险管理】信贷生命周期之风险管理
- 假定一种编码的编码范围是a-y的25个字母,形成一个数组如下: a,aa,aaa,aaaa,aaab,aaac,...yyyy 其中a的Index为0aa的Index为1aaa为2,以此类推。
- 云服务器1:云服务器能干什么
- html5---拖放demo----拖放图片
- Persistence Query
- 微信小程序配置服务器域名和业务域名
- Spring Cloud 极简入门
- 十八年努力,我才能与你一起喝咖啡(转于《读者》)
- [转载备用]微信直播的优势及微信直播搭建过程(点赞:主播妹子有点靓哦)
- 哈佛结构和冯诺依曼结构