(1)查詢學生的基本信息;
select * from S;
(2)查詢“CS”系學生的基本信息;select * from S where Sdept =’CS’;
(3)查詢“CS”系學生年齡不在19到21之間的學生的學號、姓名; select Sno, Sname from S
(4)找出最大年齡;select max(Sage) from S;
(5)找出“CS”系年齡最大的學生,顯示其學號、姓名; select * from S where Sage = (select max(Sage) from S where Sdept = 'CS');
(6)找出各系年齡最大的學生,顯示其學號、姓名;select Sno, Sname from S where Sage in (select max(Sage) from S group by Sdept);
(7)統(tǒng)計“CS”系學生的人數(shù);select count(*) from S;
(8)統(tǒng)計各系學生的人數(shù),結(jié)果按升序排列; select Sdept, count(*) from S group by Sdept Order by count(*) asc;
(9)按系統(tǒng)計各系學生的平均年齡,結(jié)果按降序排列;select Sdept, avg(Sage) as AVG from group by Sdept order by AVG desc;
(10)查詢每門課程的課程名; select Cname from C;
(11)查詢無先修課的課程的課程名和學時數(shù);select Cname, Ccredit from C where Cpno is null;
(12)統(tǒng)計無先修課的課程的學時總數(shù);select sum(Ccredit) from C where Cpno is null;
(13)統(tǒng)計每位學生選修課程的門數(shù)、學分及其平均成績;select Sno ,count(SC.Cno), avg(Grade),Sum(C.Credit) from SC,C where SC.Cno = C.Cno group by Sno;
(14)統(tǒng)計選修每門課程的學生人數(shù)及各門課程的平均成績;select Cno, count(Sno) as num, avg(Grade) as Avg from SC group by Cno;
(15)找出平均成績在85分以上的學生,結(jié)果按系分組,并按平均成績的升序排列; select S.Sdept ,avg(Grade) as Avg , S.Sname as 'name' from S left join SC on S.Sno = SC.Sno group by Sdept,S.Sname having avg(Grade) > 85 order by avg(Grade);
(16)查詢選修了“1”或“2”號課程的學生學號和姓名; select S.Sno, S.Sname from S, SC where (SC.Cno = 1 or SC.Cno = 2) and S,Sno = SC.Sno group by S.Sno, S.Sname order by S.Sno, S.Sname;
(18)查詢選修了課程名為“數(shù)據(jù)庫系統(tǒng)”且成績在60分以下的學生的學號、姓名和成績;
select S.Sno , S.Sname ,SC.Grade from S ,SC, C where C.Cname = '數(shù)據(jù)庫' 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 not in (select Sno from SC);
(21)查詢選修了3門以上課程的學生學號; select Sno from SC group by Sno having count(Cno)>=3;
(22)查詢選修課程成績至少有一門在80分以上的學生學號; select S.Sno from S left join SC on SC.Sno = S.Sno where Grade > 80 and Grade is not null group by S.Sno order by S.Sno
(23)查詢選修課程成績均在80分以上的學生學號; select Sno, Sname from S where Sno in (select Sno from SC group by Sno having avg(Grade) >=80);
(24)查詢選修課程平均成績在80分以上的學生學號; select Sno, Sname from S where Sno in (select Sno from SC group by Sno having avg(Grade) >=80);
|
|
|