实验报告-数据查询

一、实验目的:

1.观察查询结果, 体会SELECT语句实际应用;

2.要求学生能够在查询分析器中使用SELECT语句进行简单查询。

3. 熟练掌握简单表的数据查询、数据排序和数据连接查询的操作方法。

4. 掌握子查询的表示。

5. 熟练掌握数据查询中的分组、统计、计算和组合的操作方法。

二、实验环境:

SQL Server 2014

 

三、实验内容:

《实验二数据查询》:文档中的第367101213152021252933小题

3.      查询选修1号 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列;

select Sno,Grade

from SC

where Cno='1'

orderby Grade DESC,Sno ASC

6.      查询缺少了成绩的学生的学号和课程号。

select Sno,Cno

from SC

where Grade isNULL

7.      查询每个学生的学号,姓名,选修的课程名,成绩;

select Student.Sno,Sname,Cname,Grade

from Student,Course,SC

where Student.Sno=SC.Sno and SC.Cno=Course.Cno

10.   查询每门课程的先行课程的课程名称,学分;

selectFirst.Cname,Second.Cname,Second.Ccredit

from Course First,Course Second

whereFirst.Cpno=Second.Cno

12.   查询每一门课的间接先行课的课程名称;

select a.Cname,b.Cname,c.Cname

from Course a,Course b,Course c

where a.Cpno=b.Cno and b.Cpno=c.Cno

13.   查询所在系部为“MA”且选修了高等数学课程的学生姓名,年龄,性别;

select Sname,Sage,Ssex

from Student,SC,Course

where Student.Sdept='MA'and Student.Sno=SC.Sno and SC.Cno=Course.Cno  and Course.Cname='数学'

15.   查询选修了数据结构课程,且成绩在90分以上的学生姓名,年龄;

select Sname,Sage

from Student,SC,Course

where Student.Sno=SC.Sno and SC.Grade>90 and SC.Cno=Course.Cno and Course.Cname='数据结构'

20.   查询选修了全部课程的学生的姓名;

select Sname

from Student

wherenotexists

    (

            select*

            from Course

            wherenotexists

                (

                   select*

                   from SC

                   where Sno=Student.Sno and Cno=Course.Cno

                )

    )

21.   查询至少选修了学号为“201215121”的学生所选修的全部课程的学生学号和姓名;

selectDISTINCT Sno

from SC SCX

wherenotexists

    (

            select*

            from SC SCY

            where SCY.Sno='201215122'andnotexists

                (

                   select*

                   from SC SCZ

                   where SCZ.Sno=SCX.Sno and SCZ.Cno=SCY.Cno

                )

    )

25.   查询选修了操作系统课程的学生人数;

selectCOUNT(*)as OS

from SC,Course

where SC.Cno=Course.Cno and Course.Cname='操作系统'

29.   查询选修了数据库课程的最高分,平均分;

selectMAX(Grade)as High,AVG(Grade)as average

from SC,Course

where SC.Cno=Course.Cno and Course.Cname='操作系统'

33.   查询每个学生的学号,姓名,所获得的总学分(成绩大于等于60,则获得该门课程的学分);

select Student.Sno,Sname,sum(Ccredit)as total_credit

from Student,SC,Course

where Student.Sno=SC.Sno and SC.Cno=Course.Cno and SC.Grade>=60

groupby Student.Sno,Student.Sname


《实验二数据查询_part2:文档中的第4610172225小题文档中的第4610172225小题

4.      找出工程项目J2使用的各种零件的名称及其数量

select PNAME,QTY

from SPJ,P

where JNO='J2' and SPJ.PNO=P.PNO

6.    找出使用上海产的零件的工程名称

select DISTINCTJNAME

from SPJ,S,J

where S.CITY='上海' and S.SNO=SPJ.SNO and SPJ.JNO=J.JNO

10.   找出供应工程J1零件为红色的供应商号码

select S.SNO

from SPJ,P,S

where JNO='J1' and COLOR='红' andP.PNO=SPJ.PNO and S.SNO=SPJ.SNO

17.   找出没有使用天津供应商生产的红色零件的工程名称

select J.JNAME

from SPJ,P,S,J

where S.CITY!='天津' andCOLOR='红' andP.PNO=SPJ.PNO and S.SNO=SPJ.SNO and J.JNO=SPJ.JNO

22.   找出提供零件种类超过了2种的供应商号码

select SNO

from SPJ

GROUP BYSNO

HAVING COUNT(DISTINCT PNO)>2

25.找出为3个以上的工程提供零件的供应商名称

select SNAME

from SPJ,S

where S.SNO=SPJ.SNO

group bySNAME

having COUNT(DISTINCT JNO)>3

猜你喜欢

转载自blog.csdn.net/qq_40956679/article/details/80716534