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

 时间:2026-02-14 07:32:22

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

select *

from student

where sno not like '%[235]'

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

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

select sno,cno

from sc

where grade is null

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

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

select sno,grade

from sc

where cno='c02'

order by grade desc

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

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

select sum(grade) as '9512101总成绩'

from sc

where sno='9512101'

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

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

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

from sc

group by sno

having count(*)>=4

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

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

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)

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

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

7、① 请分别用等值连接、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='信息系'

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

8、l JOIN连接查询

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

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

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

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

  • Mysql创建数据库及表的方法-可视化软件Navicat
  • 女性需要的八大营养
  • 欧路词典怎么打开单击后弹窗显示解释功能
  • jquery 怎么停止函数执行
  • Python中列表元素索引的获取
  • 热门搜索
    pdca是什么意思 北上广是什么意思 adobe是什么 母亲节送什么花 实质是什么意思 distance是什么意思 sw是什么 血崩是什么意思 什么用英语怎么说 秋天是什么颜色的