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='男' );

标签:courseid,练习,查询,score,student,MySQL,where,select

来源: https://www.cnblogs.com/zhangyang4674/p/11604017.html

mysql查询所有姓王的信息_MySQL的查询练习相关推荐

  1. mysql查询所有姓王的信息_MySQL(4)— 数据查询

    四.数据查询(DQL) 4-1.查询指定字段 select 完整 语法: select [distinct] 字段名1 [as] [别名],字段名2 [as] [别名] from 表1 [ left ...

  2. 数据库 查询计算机系姓王,数据库实验3简单查询和连接查询

    实验2数据库简单查询 一.实验目的 1.掌握SQL查询语句的基本语法与用法.熟练掌握简单表的数据查询 2.掌握数据库表的各种连接查询,包括内连接和外连接查询 二.实验内容 (一)数据库和表及表中的数据 ...

  3. mysql查询动态表名的数据类型_Mysql中查询某个数据库中所有表的字段信息

    前言 有时候,需要在数据库中查询一些字段的具体信息,而这些字段又存在于不同的表中,那么我们如何来查询呢? 在每一个数据库链接的information_schema数据库中,存在这样一张表--COLUM ...

  4. mysql查询姓王的信息代码_MySQL查询语句练习题

    1.创建student和score表 CREATE  TABLE  student ( id  INT(10)  NOT NULL  UNIQUE  PRIMARY KEY  , name  VARC ...

  5. mysql 所有表的字段信息_mysql如何查询所有表和字段信息

    mysql查询所有表和字段信息的方法: 1.根据库名获取所有表的信息 SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = 'e ...

  6. mysql查询所有男生信息_MySQL 数据查询

    --查询学生表的所有字段 SELECT * fromstudent;--查询学生表的学号,姓名,性别字段 SELECT sNo,sName,sex fromstudent;--查询查询学生表的学号,姓 ...

  7. 数据库 查询计算机系姓王,数据库上机实验报告——SQL Server 2008 简单查询.doc

    实验题目SQL Server 2008 简单查询实验时间2016年5月13日实验地点T616实验成绩 实验性质□验证性 √设计性 □综合性教师评价: □算法/实验过程正确: □源程序/实验内容提交 □ ...

  8. mysql查找各科分数相同的学生_mysql中 查询各科成绩都在80以上的学生的姓名

    最近遇到一个关于mysql的查询的问题,就是在成绩表里查询各科成绩都在80以上(含80分)的学生姓名,在网上找了一个例子,供大家参考学习: 1. 2.也有人在网上用了别外的办法来查找,如下: 使用了分 ...

  9. 查询供应商姓孙的MySQL_MySQL数据库操作--查询

    一,条件 where后面支持多种运算符,进行条件的处理 比较运算 逻辑运算 模糊查询 范围查询 空判断 使用where子句对表中的数据筛选,符号条件的数据会出现在结果集中 语法如下: select 字 ...

最新文章

  1. pwa js_如何在互联网信息亭中实现PWA和Barba.js
  2. opencv---JPEG图像质量检测代码
  3. Python 实现图片轮播及音乐循环播放
  4. 软件架构:模块、组件、微服务总结
  5. A饭福利,AMD Mantle API获众多游戏开发商青睐!
  6. php base64_decode 图片,php base64保存为图片,带格式解析
  7. 如何配置Smarty模板
  8. sql server 快照_添加新文章,删除文章,更改快照文件夹路径和SQL Server复制中的数据筛选器行
  9. Hadoop(十二)MapReduce概述
  10. 物联网时代的技术迷雾
  11. (12.05)Java小知识!
  12. OpenSER安装配置指南
  13. 希尔密码 matlab,非数学专业线性代数教学设计
  14. 记录一个去底色转换为透明图片的在线工具
  15. 谷歌、百度循环多次翻译、语音下载python脚本
  16. 电机控制系统php,步进电机调速控制系统资料(原理图+单片机源码)
  17. Python-元组字典集合及其内置方法
  18. 144hz和60hz测试软件,144hz和60Hz显示器的区别有哪些?60Hz与144Hz显示器玩游戏差别对比评测...
  19. 深入讨论DECLARE_HANDLE(HINSTANCE)
  20. Vegas 使用教程(二)如何准备素材和如何导入Vegas

热门文章

  1. docker 中 安装 openssh-server
  2. mysql-5.6.24-win32.zip 下载 安装 配置 创建数据库
  3. linux里shell中的test代表的意义
  4. Bytom国密网说明和指南
  5. 设计模式之享元(flyweight)模式
  6. Jquery 同个类名中点击的显示其他隐藏的效果
  7. iOS-实现验证码倒计时功能(1)
  8. 【转】Tomcat中部署java web应用程序
  9. u盘安装CENTOS后,启动missing operating system ,只能用U盘才能启动系统
  10. PowerShell 在 SharePoint 2010 自动化部署中的应用(2)-编译打包