广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    sql server 对数据库 对表的基本操作(2)

    来源:网络收集  点击:  时间:2024-03-29
    【导读】:
    利用sql server 对数据库 对表的基本操作(2)工具/原料moresql server方法/步骤1/9分步阅读

    ①从学生表中查询学号的最后一位不是2,3,5的学生的情况。

    select *

    from student

    where sno not like %

    2/9

    ①查询无考试成绩的学生的学号和相应的课程号。

    select sno,cno

    from sc

    where grade is null

    3/9

    ①查询选修了课程“c02”的学生学号及成绩,查询结果按成绩降序排列。

    select sno,grade

    from sc

    where cno=c02

    order by grade desc

    4/9

    ①查询学号为9512101的学生考试总成绩。

    select sum(grade) as 9512101总成绩

    from sc

    where sno=9512101

    5/9

    ①查询选课门数大于等于4门的学生的学号、平均成绩和选课门数。

    select sno,count(*) as 选课门数,avg(grade) as 平均成绩

    from sc

    group by sno

    having count(*)=4

    6/9

    ①查询没有选修全部课程的学生学号、姓名。

    select student.sno,sname,count(sc.cno)as 选课门数

    from student left join sc on student.sno=sc.sno

    group by student.sno,sname

    having count(sc.cno)(select count(*)from course)

    注意:这样可以把没有选修的学生查询出来。

    7/9

    ①请分别用等值连接、join连接查询信息系选修VB课程的学生的成绩,要求列出学生姓名,课程名和成绩。

    l等值连接

    select sname,cname,grade

    from sc,student,course

    where sc.sno=student.sno and sc.cno=course.cno and course.Cname=VB and student.Sdept=信息系

    8/9

    lJOIN连接查询

    select sname,cname,grade

    from sc join student on sc.sno=student.sno join course on sc.cno=course.cno

    where Cname=VB and Sdept=信息系

    ①查询与刘晨在同一个系的学生。

    select a.sname,a.sdept

    from student a,student b

    where a.Sdept=b.Sdept and b.sname=刘晨 and a.sname!=b.sname

    9/9

    ①查询各科成绩前三名的记录:(不考虑成绩并列情况)(思路:利用row_number()over(partition by 列名 order by 列名 desc)进行分组编号)

    select *

    from (select cno,sno,row_number()over(partition by cno order by grade desc) as 排名 from sc) temp

    where 排名4

    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_373315.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-05 02:59:03  耗时:0.023
    0.0234s