• 数据库例题


    数据库查询,例题备注,可以在以后遇到类似问题,查看查询方法

    假设使用如下命令建立了一个grade表:
    create table grade(low int,upp int,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 t1.Sno,t1.Cno,t2.rank
    from Score t1
    left join grade t2
    on t1.degree between t2.low and t2.upp


    查询score中选学多门课程的同学中分数为非最高分成绩的记录。
    select Sno from Score group by Sno having COUNT(Sno) > 1

    select distinct Sno from Score where degree
    in (select MAX(degree) from Score group by Cno)

    select * from Score where Sno in
    (select Sno from Score group by Sno having COUNT(Sno) > 1)
    and Sno not in
    (select distinct Sno from Score where degree
    in (select MAX(degree) from Score group by Cno))

    查询“张旭“教师任课的学生成绩。
    select * from Teacher where Tname = '张旭'
    select * from course
    select * from score

    select * from Teacher t1 full join Course t2
    on t1.Tno = t2.Tno
    full join Score t3
    on t2.Cno = t3.Cno
    where t1.Tname = '张旭'
    查询选修某课程的同学人数多于5人的教师姓名。
    select Tname from Teacher where Tno in (
    select Tno from Course where Cno in
    (select Cno from Score group by Cno having COUNT(Cno)>5)
    )


    查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
    select * from Teacher
    where (Depart = '计算机系' or Depart = '电子工程系')
    and Prof in
    (
    select Prof from Teacher
    group by Prof
    having COUNT(*) <2
    )


    查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.
    select * from Score where Cno = '3-105' and DEGREE >
    (select MAX(Degree) from Score where Cno = '3-245')

  • 相关阅读:
    AutoLISP圆内接多边形
    AutoLISP以直线为基线添加文字
    jquery easyuidatagrid 如何清空数据
    MyBatis直接执行SQL查询及批量插入数据
    mappers文件中的#{}语法与${}语法的区别
    在windows7桌面上新建一个快捷方式,指向cmd命令窗口
    ResultSet转换List或直接遍历解决null问题
    linux命令
    flash build 4.6 报错 内存不足,无法加载...
    关于linux安装openoffice无法启动
  • 原文地址:https://www.cnblogs.com/yunpeng521/p/7073626.html
Copyright © 2020-2023  润新知