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. 查询SQLServer的启动时间

    --2008及之后版本才有 SELECT sqlserver_start_time FROM sys.dm_os_sys_info

  2. Cygwin: connection closed by ::1

    问题描述:在Win7下Cygwin中,使用ssh localhost命令, 出现Connectionclosedby::1的问题. 解决方案:1.我的电脑-管理-找到CYGWINsshd. 2.右键 ...

  3. sqlserver linkserver

    --创建链接服务器exec sp_addlinkedserver    'srv_lnk','','SQLOLEDB','远程服务器名或ip地址'exec sp_addlinkedsrvlogin ' ...

  4. TYVJ P1020 寻找质因数

    做题记录:2016-08-08 描述 给出N个数字,试求质因数最大的数字. 输入格式 第一行,一个整数N,表示数字个数.接下来N行,每行一个整数A_i,表示给出的数字. 输出格式 一个整数,表示质因数 ...

  5. 转:Web前端,高性能优化

    高性能HTML 一.避免使用iframe iframe也叫内联frame,可将一个HTML文档嵌入另一个HTML文档中. iframe的好处是,嵌入的文档独立于父文档,通常也借此使浏览器模拟多线程.缺 ...

  6. 【POJ】3150 Cellular Automaton(矩阵乘法+特殊的技巧)

    http://poj.org/problem?id=3150 这题裸的矩阵很容易看出,假设d=1,n=5那么矩阵是这样的 1 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 ...

  7. OpenCV Show Image cvShowImage() 使用方法

    新版的OpenCV在所有的函数和类前都加上了cv或Cv,这样很好的避免了区域污染(namespace pollution),而且不用在前面加‘cv::’,非常的使用.像之前的imshow()函数被现在 ...

  8. Odoo Auto Backup Database And Set Linux task schedualer

    First ,Write Database Backup Script: pg_dump -Fc yourdatabasename > /home/yourfilepath/yourdataba ...

  9. https资料

    1.HTTPS的七个误解   http://blog.httpwatch.com/2011/01/28/top-7-myths-about-https/ 中文 http://www.cnblogs.c ...

  10. Everything文件名实时搜索||解决局域网文件共享问题

    内容概要:Everything中文版下载地址及使用.用Everything轻松解决局域网文件共享问题.Everything语言设置问题 另:Everything只支持NTFS格式的磁盘(工作原理的缘故 ...