|
本帖最后由 xiaoni 于 2014-6-14 22:42 编辑
第一题:select T1.Stuid,StuName,count(courseid) as CountCcurse,sum(score) as SumScore from [tblstudent$]t1,[tblscore$]t2 where t1.stuid=t2.stuid group by T1.stuid,stuname
第二题:select t5.stuid,t5.stuname from [tblstudent$]t5 where t5.stuid not in(SELECT stuid from(select t1.StuId,StuName from [tblstudent$]t1,[tblcourse$]t2,[tblscore$]t3,[tblteacher$]t4 where t1.stuid=t3.stuid and t3.courseid=t2.courseid and t2.teaid=t4.teaid and teaname="叶平" group by t1.stuid,stuname))或另一种嵌套查询
第二题嵌套:select stuid,stuname from [tblstudent$] where stuid not in(select stuid from [tblscore$] where courseid in(select courseid from [tblcourse$] where teaid in(select teaid from [tblteacher$] where teaname="叶平")))
第三题:select t3.stuid,stuname from [tblstudent$]t3,(select t1.stuid,t1.score,t2.score from (select stuid,score from [tblscore$] where courseid="002")t1,(select stuid,score from [tblscore$] where courseid="001")t2 where t1.stuid=t2.stuid and t1.score<t2.score)t4 where t3.stuid=t4.stuid
第三题另类方法:select t1.stuid,stuname from [tblstudent$]t1,(select stuid from [tblscore$] where courseid in("001","002") group by stuid having count(1)=2 and first(score)<last(score))t2 where t1.stuid=t2.stuid
第四题:select t1.stuid,stuname from [tblstudent$]t1 left join [tblscore$]t2 on t1.stuid=t2.stuid group by t1.stuid,stuname having count(courseid)<(select count(*) from(select distinct courseid from [tblscore$]))
第五题:select stuid,stuname from [tblstudent$] where stuid in(select stuid from [tblscore$] where courseid in(select courseid from [tblscore$] where stuid="1001")) |
|