数据库实验数据查询语言

database

(1)查询学生的基本信息;

 

 select*from S;

 

     

 

(2)查询“CS”系学生的基本信息;       

select*from S where Sdept =’CS’;

(3)查询“CS”系学生年龄不在19到21之间的学生的学号、姓名;  

select Sno, Sname from S 

where Sdept = ‘CS’ and Sage not

Between19and21;

 

             

(4)找出最大年龄;     

selectmax(Sage) from S;

(5)找出“CS”系年龄最大的学生,显示其学号、姓名;

select*from S where

Sage = (selectmax(Sage) from S where Sdept ="CS");

  

(6)找出各系年龄最大的学生,显示其学号、姓名;  

select Sno, Sname from S 

where Sage in

(selectmax(Sage) from S groupby Sdept);

           

(7)统计“CS”系学生的人数;  

selectcount(*) from S;

(8)统计各系学生的人数,结果按升序排列;      

select Sdept, count(*) from S groupby Sdept

Orderbycount(*) asc;

             

(9)按系统计各系学生的平均年龄,结果按降序排列;

select Sdept, avg(Sage) asAVGfrom

groupby Sdept

orderbyAVGdesc;

(10)查询每门课程的课程名;

select Cname from C;

              

(11)查询无先修课的课程的课程名和学时数;

select Cname, Ccredit from C where Cpno isnull;

            

(12)统计无先修课的课程的学时总数;

selectsum(Ccredit) from C 

where Cpno isnull;

              

(13)统计每位学生选修课程的门数、学分及其平均成绩;

select Sno ,count(SC.Cno), avg(Grade),Sum(C.Credit)

from SC,C

where SC.Cno = C.Cno

groupby Sno;

         

(14)统计选修每门课程的学生人数及各门课程的平均成绩;

select Cno, count(Sno) as num, avg(Grade) asAvg

from SC

groupby Cno;

(15)找出平均成绩在85分以上的学生,结果按系分组,并按平均成绩的升序排列;

select S.Sdept ,avg(Grade) asAvg , S.Sname as"name"from S

leftjoin SC on S.Sno = SC.Sno

groupby Sdept,S.Sname

havingavg(Grade) >85orderbyavg(Grade);

(16)查询选修了“1”或“2”号课程的学生学号和姓名;

select S.Sno, S.Sname from S, SC

where (SC.Cno =1or SC.Cno =2)

and S,Sno = SC.Sno groupby S.Sno, S.Sname

orderby S.Sno, S.Sname;

(18)查询选修了课程名为“数据库系统”且成绩在60分以下的学生的学号、姓名和成绩;

     

select S.Sno , S.Sname ,SC.Grade from S ,SC, C 

where C.Cname ="数据库"

and Grade <60

and SC.Cno = C.Cno

and SC.Sno = S.Sno;

(19)查询每位学生选修了课程的学生信息(显示:学号,姓名,课程号,课程名,成绩);

select*from S,C,SC 

where S.Sno = SC.Sno

and C.Cno = SC.Cno;

(20)查询没有选修课程的学生的基本信息;

select*from S 

where Sno notin (select Sno from SC);

(21)查询选修了3门以上课程的学生学号;

select Sno 

from SC

groupby Sno

havingcount(Cno)>=3;

(22)查询选修课程成绩至少有一门在80分以上的学生学号;

select S.Sno 

from S leftjoin SC on SC.Sno = S.Sno

where Grade >80and Grade isnotnull

groupby S.Sno

orderby S.Sno

(23)查询选修课程成绩均在80分以上的学生学号;

select Sno, Sname from S 

where Sno in

(select Sno from SC groupby Sno havingavg(Grade) >=80);

(24)查询选修课程平均成绩在80分以上的学生学号;

select Sno, Sname from S 

where Sno in

(select Sno from SC groupby Sno havingavg(Grade) >=80);

 

以上是 数据库实验数据查询语言 的全部内容, 来源链接: utcz.com/z/533908.html

回到顶部