欢迎来到我的范文网!

报考学号查询

教学参考 时间:2020-05-11

【www.myl5520.com--教学参考】

查询补充练习参考答案
篇一:报考学号查询

查询补充练习参考答案
篇二:报考学号查询

报考学号查询。

查询选修了数据库的学生和姓名
篇三:报考学号查询

查询选修了“数据库原理”的学生的学号和姓名。

select student.sno ,sname

from student ,sc ,course

where student .sno =sc.sno and sc.cno=course.cno and course.cname='数据库原理'

SQL查询练习参考答案
篇四:报考学号查询

SQL查询练习参考答案

1.分别查询学生表和学生修课表中的全部数据.

select * from student

select * from sc

2.查询计算机系的学生的姓名、年龄。

select 姓名,年龄 from student where 所在系='计算机系'

3.查询选修了c01号课程的学生的学号和成绩。

select 学号,成绩 from sc where 课程号='c01'

4.查询成绩在70到80分之间的学生的学号,课程号和成绩.

select 学号,课程号,成绩 from sc where 成绩 between 70 and 80

5.查询计算机系年龄在18到20之间且性别为"男"的学生的姓名和年龄.

select 姓名,年龄 from student where 所在系='计算机系' and 性别='男' and 年龄 between 18 and 20

6.查询9512101号学生的修课情况.

select * from sc where 学号='9512101'

7.查询c01号课程成绩最高的分数.

select max(成绩) 最高分 from sc where 课程号='c01'

select 学号,课程号,成绩 最高分 from sc where 成绩=(select max(成绩) from sc where 课程号='c01')

8.查询学生都修了哪些课程,要求列出课程号

select distinct 课程号 from sc

9.查询 Northwind 数据库中orders表的OrderID,CustomerID和OrderDate,并奖最新的订购日期(OrderDate)列在前面.

use Northwind报考学号查询。

select OrderDate,OrderID,CustomerID from orders

10.查询 Northwind 数据库中orders表的ShipCountry列以B,C,D,F开始且第三个字符为"a"的OrderID,CustomerID和ShipCountry信息.

select OrderID,CustomerID,ShipCountry from orders where ShipCountry like '[BCDF]_a%'

11.查询 Northwind 数据库中orders表的ShipCountry列不以A,B,C,D,E,F开始且最后一个字母是"a"的OrderID,CustomerID和ShipCountry信息.

select OrderID,CustomerID,ShipCountry from orders where ShipCountry like '[^ABCDEF]%A'

12.查询学生数据库中学生的最大年龄和最小年龄.

use sqllx

select max(年龄) 最大年龄,min(年龄) 最小年龄 from student

13.查询修了c02号课程的所有学生的平均成绩,最高成绩,最低成绩.

select avg(成绩) 平均成绩,max(成绩) 最高成绩,min(成绩) 最低成绩 from sc where 课程号='c02'

14.统计每个系的学生人数.报考学号查询。

select 所在系, count(*) 人数 from student group by 所在系

15.统计每门课程的修课人数和考试最高分.

select 课程号,count(*) 修课人数,max(成绩) 最高分 from sc group by 课程号

16.统计每个学生的选课门数,并按选课门数的递增顺序显示结果

select 学号,count(课程号) 选课门数 from sc group by 学号 order by count(课程号)

17.统计各系的修课的学生总数和考试的平均成绩.

select 所在系,count(*) 学生总数,avg(成绩) 平均成绩 from student st join sc on st.学号=sc.学号 group by 所在系

18.查询选课门数超过两门的学生的平均成绩和选课门数.

select 学号,count(课程号) 选课门数,avg(成绩) 平均成绩 from sc group by 学号 having count(课程号)>2

19.列出总成绩超过200分的学生,要求列出学号,总成绩

select 学号,sum(成绩) 总成绩 from sc group by 学号 having sum(成绩)>200

20.平均价格超过12.0元的书的类型(type),平均价格

,要求只计算有确定价格的图书的情况。

use pubs

select type ,avg(price) 平均价格,max(price) 最高价格

from titles group by type having avg(price)>12.0

21.查询pubs数据库的titles表中版税(royalty)为10的每类书的平均价格.

select avg(price) 平均价格 from titles where royalty=10 group by type

22.查询pubs数据库的titles表中每类图书的数目超过3本的图书的总价格.

select sum(price) 总价格 from titles group by type having count(type)>3

23.查询选修了c02 号课程的学生的姓名和所在系.

use sqllx

select 姓名,所在系 from student st,sc where st.学号=sc.学号 and sc.课程号='c02'

24.查询成绩80分以上的学生的姓名,课程号和成绩,并按成绩的降序排列结果.

select 姓名,课程号,成绩 from student st,sc where st.学号=sc.学号 and sc.成绩>80

order by 成绩 desc

--等价于下列命令

select 姓名,课程号,成绩 from student st join sc on st.学号=sc.学号 where 成绩>80

order by 成绩 desc

25.查询计算机系男生修了"数据库基础"的学生的姓名,性别,成绩

select 姓名,性别,成绩 from student st , course co,sc where st.学号=sc.学号 and

sc.课程号=co.课程号 and st.所在系='计算机系'and co.课程名='数据库基础' and st.性别='男'

26.查询学生的选课情况,要求列出每位学生的选课情况(包括未选课的学生),并列出学生的学号,姓名,修课号,修课成绩

select student.学号,姓名,课程号,成绩 from student left join sc on student.学号=sc.学号

27.列出"数据库基础"课程考试成绩前三名的学号,姓名,所在系和考试成绩.

select top 3 st.学号,姓名,所在系,成绩 from student st,course co ,sc

where st.学号=sc.学号 and co.课程号=sc.课程号 and 课程名='数据库基础' order by 成绩 desc

--或者表示为:

select top 3 st.学号,姓名,所在系,成绩 from student st join sc on st.学号=sc.学号

join course co on sc.课程号=co. 课程号

where 课程名='数据库基础' order by 成绩 desc

28查询哪些学生合选了一门课程,要求列出合选课程的学生的学号和课程号

select distinct s1.学号, s1.课程号 from sc s1 join sc s2 on s1.课程号=s2.课程号 order by s1.课程号

--29.查询哪些学生的年龄相同,要求列出年龄相同的学生的姓名和年龄.

select distinct s1.姓名,s1.年龄 from student s1 join student s2 on s1.年龄=s2.年龄 order by s1.年龄

30.查询哪些课程没有人选,要求列出课程号和课程名.

select co.课程号,co.课程名 from course co , sc

where co.课程号=sc.课程号 and co.课程号 not in(select 课程号 from sc)

31.查询有考试成绩的所有学生的姓名,修课名称,及考试成绩,要求将查询结果放在一张新的永久表(假设新表名为new_sc)中,

新表的列名分别为student_name,course_name,grade.

select 姓名 student_name,课程名 course_name,成绩 grade into new_sc

from student st join sc on st.学号=sc.学号 join course co on co.课程号=sc.课程号 where sc.成绩 is not null

32.分别查询信息系和计算机系的学生的姓名,性别,修课名称,修课成绩,并要求将这两个查询结果合并成一个结果集,

并以系名,姓名,性别,修课名称,修课成绩的顺序显示各列

select st.所在系,st.姓名,st.性别,co.课程名,sc.成绩 from student st,course co,sc

where sc. 学号=st.学号 and sc.课程号=co.课程号 and st.所在系='计算机系'

union

select st.所在系,st.姓名,st.性别,co.课程名,sc.成绩 from student st,course co,sc

where sc. 学号=st.学号 and sc.课程号=co.课程号 and st.所在系='信息系'

33用子查询实现如下查询:

1)查询选修了c01号课程的学生的姓名和所在系

select 姓名,所在系 from student where 学号

in (select 学号 from sc where 课程号='c01')

报考学号查询。

2)查询数学系成绩80分以上的学生的学号,姓名.

select 学号,姓名 from student where 学号 in (select distinct 学号 from sc where 成绩>80) and 所在系='数学系'

3)查询计算机系学生所选的课程名.

select 课程名 from course where 课程号 in (select 课程号 from sc where 学号

in (select 学号 from student where 所在系='计算机系'))

4)查询"VB"课程考试成绩前三名的学生的学号,姓名,所在系.

select 学号,姓名,所在系 from student where 学号

in (select top 3 with ties 学号 from sc where 课程号

in(select 课程号 from course where 课程名='VB') order by 成绩 desc)

--34.

insert into test_t values(null,'b1','')

insert into test_t values('1','b2','c2')

insert into test_t values('2','b3','')

insert into test_t values(null,'b4','c4')

--35

select st.学号,姓名,成绩,所在系 into test_3 from student st,sc

where st.学号=sc.学号 and st.所在系='计算机系' and sc.成绩>80

--36.

delete from sc where 成绩=50

--37

--1)

delete from sc where 成绩<50 and 学号 in(select 学号 from student where 所在系='信息系')

delete from sc

from sc join student on sc.学号=student.学号 where 所在系='信息系' and 成绩<50 --38

update sc set 成绩=成绩+10 where 课程号='c01'

--39

--1)

update sc set 成绩=成绩+10 where 学号 in (select 学号 from student where 所在系='计算机系')

and 课程号 in(select 课程号 from course where 课程名='计算机文化学')

--2)

update sc set 成绩=成绩+10 from sc join student on sc.学号=student.学号 join course on course.课程号=sc.课程号

where student.所在系='计算机系' and course.课程名='计算机文化学'*/

本文来源:http://www.myl5520.com/jiaoanxiazai/104930.html

推荐内容