zoukankan      html  css  js  c++  java
  • 45

    19.查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

    select avg(degree) from scrore where cno=( select cno from scrore group by cno having count(*)>5 and cno like '3%')

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

    select score.sno,score.cno,grade.rank from score,grade where score.Degree>grade.low and score.Degree<grade.upp

    select sno,cno,rank from score,grade where Degree between low and upp

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

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

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

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

    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) and sno=108

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

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

    27、查询出“计算机系“教师所教课程的成绩表。

    select degree from score where cno in(select cno from course where tno in(select tno from teacher where depart='计算机系'))

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

    select tname,prof from teacher where depart='计算机系' and prof not in(select prof from teacher where depart='电子工程系') union  select tname,prof from teacher where depart='电子工程系' and prof not in(select prof from teacher where depart='计算机系')

    Select tname,prof from teacher prof 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 sno,cno,degree from score where degree> any(select degree from score where cno='3-245') and cno='3-105' order by degree desc

    30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.

    select sno,cno,degree from score where degree> all(select degree from score where cno='3-245') and cno='3-105' 

    31、 查询所有教师和同学的name、sex和birthday.

    select sname as name,ssex as sex,sbirthday as birthday from student union select tname as name,tsex as sex, tbirthday as birthday from teacher

    32、查询所有“女”教师和“女”同学的name、sex和birthday.

    select sname as name,ssex as sex,sbirthday as birthday from student where ssex='女' union select tname as name,tsex as sex, tbirthday as birthday from teacher where tsex='女'

    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 )

    36、查询至少有2名男生的班号。

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

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

     select sname as '姓名', floor((to_days(now())-to_days(sbirthday))/365) as '年龄' from student

     select sname as '姓名', (year(now())-year(sbirthday)) as '年龄' from student

    39、查询Student表中最大和最小的Sbirthday日期值。

    select max(year(sbirthday)) as'最大日期',min(year(sbirthday)) as '最小日期' from student

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

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

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

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

  • 相关阅读:
    [C#]App.Config
    [转][JS]修改链接中的参数
    [转][Oracle]常见报错及处理
    [转]截图软件分享
    [转][C#]手写 Socket 服务端
    3.6的pprint写法改变了:pprint.pprint()
    版本优化-test
    python爬取豆瓣小组700+话题加回复啦啦啦python open file with a variable name
    爬豆瓣被封的解决方案
    去除列表中字符串中的空格换行等
  • 原文地址:https://www.cnblogs.com/ysdong/p/5972674.html
Copyright © 2011-2022 走看看