数据库原理与应用第三版何玉洁第六章上机练习答案

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
1
select * from Student
2
select Sname,Sage from Student
3
select Sno,Cno,Grade from SC Where Grade between 70 and 80
4
select Sname, Sage from Student where Sage between 18 and 20
5
select Top 1 Grade from SC where Cno = ‘c01’ order by Grade DESC
6
select MAX(Sage), MIN(Sage) from Student where Sdept=‘计算机系’
7
select count() from student group by Sdept
8
select Sno,count(
),Sum(Grade) from SC group by Sno
9
select Sno, Sum(Grade) from SC group by Sno having sum(Grade)>=200
10
select Sname, Sdept from Student join SC on Student.Sno = SC.Sno where Cno =‘c02’
11
select Sname,Cno,Grade from Student join SC on Student.Sno=SC.Sno where Grade >= 80 order by Grade DESC
12
select Student.Sno,Sname,Sdept from Student left join SC on Student.Sno = SC.Sno where SC.Sno is NULL
13
select Count(),Cno from SC group by Cno
14
select Cname,Semester from Course where Semester in (select Semester from Course where Cname = ‘VB’) and Cname != ‘VB’
15
select s1.Sname,s1.Sdept,s1.Sage from Student s1 join student s2 on s1.Sage=s2.Sage where s2.Sname =‘李勇’ and s1.Sname !=‘李勇’
16
select top 2 Sname,Sage from Student where Sdept = ‘计算机系’
17
select top 2 with ties Sname,Sdept,Grade from
Student join SC on Student.Sno = SC.Sno join Course on SC.Cno = Course.Cno
where Cname = ‘VB’ order by Grade DESC
18
select top 2 with ties Sno,count(
) from SC group by Sno order by count() DESC
19
select top 1 Sdept,count(
) from Student
group by Sdept order by count() DESC
20(1)
select Sname,Sdept from Student where Sno in (
select Sno from SC where Cno = ‘c01’)
20(2)
select Student.Sno,Sname Cno,Grade from Student join SC on Student.Sno = SC.Sno where Student.Sno in
(select Sno from SC where Grade >= 80
)
20(3)
select Sname from Student where Sno in (
select top 1 Sno from SC order by Grade DESC)
20(4)
select Sname,Sdept,Ssex,Grade from Student join SC on Student.Sno=SC.Sno where Student.Sno in (
select top 1 Sno from SC join Course on SC.Cno = Course.Cno where Cname = ‘数据结构’ order by Grade DESC)
21
select Sname, Sdept from Student where Sno not in (
Select Sno from SC join Course on SC.Cno=Course.Cno
where Cname=‘VB’
)
22
select Sname,Ssex from Student where Sno not in(
select Sno from SC
)
23
select top 1 Sname,Cname from
Student join SC on Student.Sno=SC.Sno join Course on SC.Cno = Course.Cno
where Student.Sno in (
select top 1 Sno from SC where Sdept='计算机系’group by Sno order by avg(Grade)
)
24
select Cname,Semester,Credit from Course
where Cno in (
select top 1 Course.Cno from SC join Course on SC.Cno = Course.Cno
where Semester between 1 and 5
group by Course.Cno order by Count(
)
)
25
select Student.Sno,Sname,Grade into Computer_Dept
from Student join SC on Student.Sno = SC.Sno

26
create table test_t
(
COL1 int,
COL2 char(10) not null,
COL3 char (10)
)
insert into test_t
values
(null,‘B1’,null),
(1,‘B2’,‘C2’),
(2,‘B3’,null)
27
delete from SC where Grade <= 50
28
delete from Course where Cno not in
(select Cno from SC)
29
delete from Student
from Student join SC on Student.Sno=SC.Sno join Course on SC.Cno = Course.Cno
where Sdept = ‘计算机系’ and Cname = ‘VB’ and Grade <60
30
delete from SC
from Course join SC on Course.Cno=SC.Cno
where Cname = ‘VB’ and Grade = (
select min(grade) from SC join Course on Course.Cno=SC.Cno
where Cname=‘VB’)
31
update Course
Set Credit = Credit + 2
where Semester = 2
32
update Course
Set Credit = 3
where Cname = ‘VB’
33
update Student
Set Sage = Sage + 1
where Sdept = ‘计算机系’
34
update SC
Set Grade = Grade + 5
from Student join SC on Student.Sno=SC.Sno join Course on SC.Cno = Course.Cno
where Sdept = ‘信息系’ and Cname = ‘计算机文化学’
35
update Course
set Credit = Credit - 1
where Cno in (
select top 1 SC.Cno from SC join Course on SC.Cno = Course.Cno
group by SC.Cno order by Count(*))

猜你喜欢

转载自blog.csdn.net/little_yuan20/article/details/108227916