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=’计算机导论’)

  • 相关阅读:
    分享一个文件的工具类
    关于itext生成pdf的新的demo(包含简单的提取txt文件的内容 和xml内容转化为pdf)
    全文检索的Demo
    dom4j操作xml的demo
    利用Java获取ip地址
    利用htmlparser读取html文档的内容
    关于pdfbox操作pdf的分享链接手长
    poi读取word的内容
    基于NPOI对Excel进行简单的操作
    “尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。”
  • 原文地址:https://www.cnblogs.com/ysdong/p/5972674.html
Copyright © 2011-2022 走看看