student表

teacher表

course表

score表

对这四个表进行一些练习。

1:查询student表中所有记录。

select *from student;

2:查询student表中name/sex/classid这些列。

select  name,sex,classid from student;

3:查询教师中不重复的单位department。

select distinct department from teacher;

distinct 列(一个或多个) 获取不重复的记录

4:查询score表中成绩再60至80之间的记录。

select *from score where degree between 60 and 80;

5:查询score表中成绩为85,86,88的记录。

select *from score where degree in (86,85,88);

6:查询student表中为95031班的或性别为女生的。

select *from student where classid=95031 or sex='女';

7:以classid列降序查询student表的所有记录。

select *from student order by desc classid ;

8:以degree降序courseid升序输出score表中所有记录。

select *from score order by courseid asc, degree desc;

9:查询95031班级的人数。

select count(id) from student where classid=95031;

10:查询score表中成绩最高者的记录。

select *from score where degree=(select max(degree) from score);

或: select id,courseid,degree order by degree desc limit 0,1;

11:查询每门课的平均数。

select courseid,avg(degree) from score group by courseid;

12:查询score表中至少2名学生选修以3开头的课程的平均分数。

select courseid, avg(degree) as average from score group by courseid having count(courseid)>1 and courseid like '3%';

13:查询score中分数大于70小于90的id列。

select  *from score where degree between 70 and 90;

14:查询学生的name列和degree列和classid列(多表查询)。

select name,degree,classid from student,score where student.id=score.id

15:查询学生的课程id课程名和degree列(多表查询)。

select coursename,degree from score,course where course.courseid=score.courseid;

16:查询学生的姓名成绩和对应课程名。(三表查询)。

select  name,degree,coursename from student,course,score where score.id=student.id and score.courseid=course.courseid;

17:查询95031班学生每门课的平均成绩(子查询)。

select avg(degree) from score where id in(select id from student where classid=95031) group by courseid;

18:查询选修3105课程高于109好同学3105课程成绩的同学记录。

select *from score where courseid=3105 and degree>(select degree from score where id=109 and courseid=3105);

19:查询成绩高于学号109课程号为3105的同学的记录。

select *from score where  degree>(select degree from score where id=109 and courseid=3105);

20:查询学号与101和108的同学同年出生的学生的记录。

select name, brithday,classid from student where year(brithday) in (select year(brithday) from student where id=108 or id=101);

21:查询张旭老师教的课程学生的成绩。

select *from score where courseid in (select courseid from course where teacherid=(select id from teacher where name='张旭'));

22:查询选修课多余5人的老师的记录。

select *from teacher where id in (select teacherid from course where courseid in (select courseid from score group by courseid having count(courseid)>5));

23:查询95033和95031班级同学的记录

select *from student where classid in (95033,95031);

24:查询88分以上成绩的课程name。

select coursename from course where courseid in(select courseid from score where degree>88);

25:查询计算机系老师所教课程同学的成绩。

select *from score where courseid in(select courseid from course where teacherid in(select id from teacher where department='计算机系'));

26:查询计算机系与电子工程系不同职称的教师的记录。

select *from teacher where department='计算机系'and professional  not in (select professional from  teacher where department='电子工程系' )

-> union

-> select *from teacher where department='电子工程系'and professional  not in (select professional from  teacher where department='计算机系' );

27:查询选修编号为3105的课程成绩至少高于部分选修3245课程学生的成绩的记录。

select *from score where courseid=3105  and degree> any(select degree from score where courseid=3245);

28:查询选修编号为3105的课程成绩高于所有选修3245课程学生的成绩的记录。

select *from score where courseid=3105  and degree> all(select degree from score where courseid=3245);

29:查询所有教师和学生的name ,sex ,brithday。

select name,sex,brithday from student

-> union

-> select name,sex,brithday from teacher;

30:查询女教师和女同学的name sex brithday。

select name,sex,brithday from student where sex='女'

-> union

->  select name,sex,brithday from teacher where sex='女';

31:查询成绩比该课程平均分低的同学的成绩。

select *from score a where degree

32:查询任课老师的name和department。

select *from teacher where id in(select teacherid from course where courseid in(select courseid from score group by courseid));

33:查询班级中至少有2名男生的班级。

select classid from student where sex='男' group by classid having count(classid)>1;

34:查询班级中不姓王的同学。

select *from student where name not like '王%';

35:查询所有学生的姓名和年龄。

select name,year(now())-year(brithday) as age from student;

36:查询学生中年龄最大和年龄最小的数据。

select max(year(now())-year(brithday)),min(year(now())-year(brithday)) from student;

37:以班号和年龄从大到小顺序查询student表中所有记录。

select *from student order by classid,year(now())-year(brithday);

38:查询男教师所上的课程。

select coursename from course where teacherid in (select  id from teacher where sex='男');

39:查询最高分同学的信息。

select *from score where degree =(select max(degree) from score);

40:查询和季军同性别的所有同学。

select *from student where sex=(select sex from student where name='季军');

41:查询和季军同性别并同班的同学的信息。

select *from student where sex=(select sex from student where name='季军') and classid=(select classid from student where name='季军');

42:查询所有选修计算机导论课程的男同学的成绩。

select *from score where courseid=(select courseid from course where coursename='计算机导论') and id in(select id from student where sex='男' );

mysql查询95031班人数_MySQL的查询练习 - osc_1ngzqx2h的个人空间 - OSCHINA - 中文开源技术交流社区...相关推荐

  1. mysql实训5答案_MySQL 实训篇 - osc_mi06gsf5的个人空间 - OSCHINA - 中文开源技术交流社区...

    一.创建student.achievement表 1. create table student(id int unsigned auto_increment primary key,name var ...

  2. mysql设置主键约束为降序_MySQL约束的概述 - osc_tko37abm的个人空间 - OSCHINA - 中文开源技术交流社区...

    MySQL约束 今日学习内容 1.DQL:查询语句 1.排序查询 2.聚合函数 3.分组查询 4.分页查询 2.约束 3.多表关系 4.范式 5.数据库备份和还原 DQL查询语句 排序 通过ORDER ...

  3. MySQL配置大小写敏感报错_mysql表名大小写敏感 - xbuding: watch and learn! - OSCHINA - 中文开源技术交流社区...

    在ubuntu下安装的mysql版本是 5.6.25-0ubuntu1 linux下的mysql的表名是大小写敏范的.而在在windows下安装的mysql是大小写不敏感的. 原因是因为lower_c ...

  4. mysql外卖怎么写_MySQL曹操外卖一 - osc_wy5qpqnh的个人空间 - OSCHINA - 中文开源技术交流社区...

    select * from goods where goodsid in(select goodsid from orderdetails where orderid in(select orderi ...

  5. 查看mysql主从复制是否成功的命令_mysql主从复制 - hong查理的个人空间 - OSCHINA - 中文开源技术交流社区...

    1.配置 my.cof 服务器A(192.168.1.2)配置如下 log-bin   = mysql-bin server-id = 1 expire-logs-days  = 7#日志设置最高7天 ...

  6. mysql 列转行union all_MySQL中的列转行 - osc_qheq8wav的个人空间 - OSCHINA - 中文开源技术交流社区...

    mysql中的列转行 在工作中遇到的一个MySQL列转行的统计: 场景 用户访问app时会跳出标签选择页面让用户选择喜欢的标签,在数据库中记录的是数组样式的字符串,数据样式大致如下: id user_ ...

  7. mysql的第一次作业_数据库入门第一次作业 - osc_2frf70qv的个人空间 - OSCHINA - 中文开源技术交流社区...

    数据库入门第一次作业 1.在某大学的<>中,用如下表来存储学生信息.其中,用户信息.星座信息和血型信息分别采用Users.Star和Blood三个表来保存,其中Users表引用了Star和 ...

  8. mysql for loop_MySQL循环语句 - Linux就该这么学的个人空间 - OSCHINA - 中文开源技术交流社区...

    mysql常见的三种循环方式:while.repeat和loop循环.还有一种goto,不推荐使用. 1.while循环 -- 设置mysql分隔符为//,也就意味着,当遇到下一个//时,整体执行SQ ...

  9. zabbix中mysql连不上的排错_zabbix使用排错 - oschina130111的个人空间 - OSCHINA - 中文开源技术交流社区...

    在linux系统中,几乎所有运行的服务都会产生相对就的日志(log),所运行的程序在出错时都会有错误提示,即使没有任何提示也可以通过"echo $"来查看运行是否成功.使用zabb ...

最新文章

  1. R语言使用car包的durbinWatsonTest函数检验回归模型的响应变量(或者残差)是否具有独立性(Independence、是否具有自相关关javascript系autocorrelated)
  2. R语言构建xgboost模型:指定特征交互方式、单调性约束的特征、获取模型中的最终特征交互形式(interaction and monotonicity constraints)
  3. 如何使用Spring优雅地处理REST异常?
  4. 解决 502、504 Gateway Time-out(nginx)
  5. {“errmsg“:“name length invalid rid: 5fbf54ef-3a02c“,“errcode“:300002}
  6. 图像滤镜艺术---微软自拍APP滤镜实现合集DEMO
  7. mysql数据库分表备份脚本_mysql 分库分表备份脚本
  8. 微信独立精彩互换抢红包系统源码ThinkPHP开源版
  9. SQL Server:专业的DateTime范围
  10. 我错了——虚拟光驱 for linux
  11. java多线程(简单介绍)
  12. Atitit java读取堵塞cmd命令行返回结果 java read maven 主要原理是另外线程读取标准流,错误流。。 回显增加out头,这样发布区分errstream和stdstream的
  13. Apache PDFBox 1.8.1 发布
  14. 微信小程序的布局css样式
  15. unicode 表情对照表
  16. 从ChargePoint到能链智电,充电服务商的价值创新
  17. Python可视化基础----从0学会matplotlib折线图,条形图,散点图
  18. ubuntu18设置屏幕旋转_[Android6.0][MTK6737] 设置屏幕旋转 270 度
  19. MVP模式基本用例开发
  20. 3dmax su 简单_【建模技巧】如何用3DMAX制作简单的绣球模型

热门文章

  1. AUTOSAR OS和OSEK OS
  2. 论文推荐:陈国生 实证化中医基础理论
  3. 【Prometheus】Alertmanager告警全方位讲解
  4. 【网页制作】CSS文本和字体属性讲解【附讲解视频】
  5. 日志框架之Logback的使用与详细配置
  6. 怎么制作游戏脚本_怎么剪游戏视频?五步教你制作绝地求生击杀合集
  7. u盘正常接入后计算机无法看到,U盘连接电脑看不到盘符怎么办?U盘在电脑上不显示盘符解决方法...
  8. Pycharm专业版安装详细教程!
  9. 语义分割评价指标mIOU
  10. Zookeeper重要概念