10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

select sno,cno from score where degree  in(select max(degree) from score)

11、查询每门课的平均成绩。

select cno,avg(degree) from score group by cno

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)

14、查询所有学生的Sname、Cno和Degree列。

select score.cno,score.degree,student.sname from score,student where student.sno=score.sno

16、查询所有学生的Sname、Cname和Degree列。

select student.sname,course.cname,score.degree from score,course,student where student.sno=score.sno and course.cno=score.cno

17、 查询“95033”班学生的平均分。

select avg(degree) from score where sno in (select sno from student where class='95033')

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列。

1.select sno,cno, rank from score  join grade on degree between low and upp

2.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 degree from score where sno=’109’)

查询选修“3-105”课程的并且成绩高于“109”号同学成绩的所有同学的记录。

select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105' )

20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。

select * from score where sno in(select sno from score group by sno having count(*)>1 ) and  degree not in(select max(degree) from score)

21、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。

select * from score where degree>(select degree from score where sno='109' and cno='3-105' )

22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。

select sno,sname,sbirthday from student where YEAR(sbirthday)=(select YEAR(sbirthday) from student where sno=’108’)

23、查询“张旭“教师任课的学生成绩。

select * from score  where cno in(select cno from course where tno=(select tno from teacher where tname='张旭'))

24、查询选修某课程的同学人数多于5人的教师姓名。

select tname from teacher where tno=(select tno from course  where cno=(select cno from score group by cno having count(*)>5))

、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。

select tname,prof from teacher where prof not in(select prof from teacher where depart=’计算机系’and prof in(select prof from teacher where 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') order by Degree desc

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')

33、 查询成绩比该课程平均成绩低的同学的成绩表。

select * from score a where degree<(select avg(degree) from score b where b.cno=a.cno)

34、查询所有任课教师的Tname和Depart.

select tname,depart from teacher where tno in(select tno from course where cno in(select cno from score))

35 、查询所有未讲课的教师的Tname和Depart.

select tname,depart from teacher where tno in(select tno from course where cno not in(select cno from score))

37、查询Student表中不姓“王”的同学记录。

select * from student where sname not like '王%'

38、查询Student表中每个学生的姓名和年龄。

select sname,year(now())-year(sbirthday) from student

41、查询“男”教师及其所上的课程

select tname,cname from teacher,course where teacher.tno=course.tno and tsex='男'

42、查询最高分同学的Sno、Cno和Degree列。

select sno,cno,degree  from score where degree=(select max(degree) from score)

43、查询和“李军”同性别的所有同学的Sname.

select sname from student where  ssex in(select ssex from student where sname='李军')

44、查询和“李军”同性别并同班的同学Sname.

select Sname from Student where Ssex = (select Ssex from Student where Sname='李军') and class in(select class from student where sname='李军')

45、查询所有选修“计算机导论”课程的“男”同学的成绩表。

select * from score where cno in(select cno from course where cname='计算机导论') and sno in(select sno from student where ssex='男')

mysql select 练习题的更多相关文章

  1. MySQL SELECT练习题*28

    -- (1)用子查询查询员工“张小娟”所做的订单信息. SELECT * FROM order_master WHERE saler_no = ( SELECT employee_no FROM em ...

  2. 【Python全栈-后端开发】MySQL数据库-练习题

    MySQL数据库-练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号 ...

  3. mysql 及练习题

    if() 函数的用法 IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false, mysql,'女','男') as sex fr ...

  4. MYSQL经典练习题,熟悉DQL

    MYSQL经典练习题 (本练习题可让你熟悉DQL,快速的上手DQL) 首先,先在数据库中建立基本数据库以及表项: DROP DATABASE IF EXISTS `test`; CREATE DATA ...

  5. mysql select日期格式

    mysql表中datatime类型存储为2016-01-10,C#直接select 后,在datatable里面看,变成01/10/2016,需要还原回去,使用select DATE_FORMAT(列 ...

  6. mysql select

    select 查询: 赋值:赋值不能应用在where中,因为where操作的是磁盘上的文件,可以应用在having筛选中. 例:select (market_price-shop_price) as ...

  7. mysql select 格式化输出

    select * from test\G; MySQL的客户端命令行工具,有很多方便使用者的特性,某些方面甚至可以说比Oracle的sqlplus更加人性化.当然从整体来说,还是sqlplus更加方便 ...

  8. mysql SELECT FOR UPDATE语句使用示例

    以MySQL 的InnoDB 为例,预设的Tansaction isolation level 为REPEATABLE READ,在SELECT 的读取锁定主要分为两种方式:SELECT ... LO ...

  9. MySQL select into 和 SQL select into

    现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去,虽然可以用以下语句进行复制,总觉得不爽,希望各位帮助下我,谢谢.  answer 01: create table d ...

随机推荐

  1. 【HTML5】Web存储

    HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前,这些都是由 coo ...

  2. JavaScript案例六:简单省市联动(NBA版)

    JavaScript实现简单省市(NBA版)联动 <!DOCTYPE html> <html> <head> <title>JavaScript实现简单 ...

  3. 记录sqoop同步失败问题解决过程,过程真的是很崎岖。(1月6日解决)

    记录sqoop同步失败问题解决过程,过程真的是很崎岖.事发原因:最近突然出现sqoop export to mysql时频繁出错.看了下日志是卡在某条数据过不去了,看异常.看sqoop生成的mr并未发 ...

  4. 编译x264 for ios

    Tested with: x264-snapshot-20140914-2245  我用的是x264-snapshot-20150813-2245.tar.bz2 Xcode 7 依赖gas-prep ...

  5. android native开发时:java.lang.UnsatisfiedLinkError: Native method not found的处理

    这个异常一般是由于JNI的链接器不能正常识别C++的函数名造成的.处理的方法是用exern "C" {},来包裹需要export的C++的native方法. 如果native的方法 ...

  6. 最短路(Dijkstra) POJ 1062 昂贵的聘礼

    题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...

  7. win产品密钥大搜集

    Win7产品密钥大收集 一.先说的还是4枚神Key如下: KH2J9-PC326-T44D4-39H6V-TVPBY TFP9Y-VCY3P-VVH3T-8XXCC-MF4YK 236TW-X778T ...

  8. COJ969 WZJ的数据结构(负三十一)

    WZJ的数据结构(负三十一) 难度级别:D: 运行时间限制:3000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 A国有两个主基站,供给全国的资源.定义一个主基站 ...

  9. java中的Integer的toBinaryString()方法

    在一次面试的过程中,遇到过这样的题目,题目的大概意思是:让写出Integer类中的toBinaryString()方法 也就是说,把Integer转换为Binary的过程写出来 但是我蒙的,在查了JD ...

  10. zabbix自定义键值原理

    子配置文件的配置 为了便于维护和分类管理,UserParameter的内容可以单独写一个配置文件 # vim /usr/local/zabbix/etc/zabbix_agentd.conf Incl ...