|
第一题:select t1.stuid,stuname,score from[tblstudent$]t1,[tblcourse$]t2,[tblscore$]t3 where t1.stuid=t3.stuid and t2.coursename="数据库" and t2.courseid=t3.courseid and t3.score<60
第二题:SELECT * from (select stuname,coursename,score from [tblstudent$]t1,[tblcourse$]t2,[tblscore$]t3,[tblteacher$]t4 where t1.stuid=t3.stuid and t2.courseid=t3.courseid and t2.teaid=t4.teaid and teaname="叶平")a where not exists(select coursename from (select stuname,coursename,score from [tblstudent$]t1,[tblcourse$]t2,[tblscore$]t3,[tblteacher$]t4 where t1.stuid=t3.stuid and t2.courseid=t3.courseid and t2.teaid=t4.teaid and teaname="叶平")b where a.coursename=b.coursename and a.score<b.score)
第三题:select t2.courseid,coursename,course_count from (select courseid,count(*) as course_count from [tblscore$] group by courseid)t1 right join [tblcourse$]t2 on t1.courseid=t2.courseid
第四题解法1:select * from [tblscore$]a where (select count(*) from[tblscore$]b where a.score=b.score and a.courseid<>b.courseid)>=1 order by courseid,score desc
第四题解法2:select distinct a.* from[tblscore$]a inner join [tblscore$]b on a.courseid<>b.courseid and a.score=b.score order by a.courseid,a.score desc
第四题解法3:select distinct a.* from[tblscore$]a,[tblscore$]b where a.courseid<>b.courseid and a.score=b.score order by a.courseid,a.score desc
第五题解法1:select a.* from [tblscore$] a where a.stuid in (select top 2 b.stuid from [tblscore$]b where b.courseid= a.courseid order by score desc) order by courseid,stuid
第五题解法2:SELECT A.* FROM [tblscore$] A WHERE (SELECT 1+COUNT(*) FROM [tblscore$] B WHERE B.courseid=A.courseid AND B.score>A.score)<=2 ORDER BY courseid, score DESC
第六题:select t1.Stuid,format(avg(score),"0.00") as Score_Avg from [tblscore$]t1,(select stuid from [tblscore$] where score <60 group by stuid having count(*)>=2)t2 where t1.stuid=t2.stuid group by t1.stuid
|
|