Excel精英培训网

 找回密码
 注册
查看: 8435|回复: 15

数据透视表中级班练习八

[复制链接]
发表于 2014-6-3 18:24 | 显示全部楼层 |阅读模式
本帖最后由 JLxiangwei 于 2014-9-16 14:59 编辑

数据透视表中级班练习八.rar (38.21 KB, 下载次数: 82)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-6-3 18:27 | 显示全部楼层
本帖最后由 lnjyzxp 于 2014-6-4 22:00 编辑

练习八都出来了,老师辛苦了!我是箫风,这是我的另一个马甲,在向老师的帮助下,练习终于做完了!代码如下:
序号
  
要求
  
 
3查询所有同学的学号、姓名、选课数、总成绩select A.StuId,StuName,CountCourse,  SumScore from (select StuId,count(CourseId) as CountCourse,sum(Score) as  SumScore from [tblScore$] group by StuId) A left join [TblStudent$] B on  A.StuId=B.StuId
5查询没学过“叶平”老师课的同学的学号、姓名;select StuId,StuName  from [tblStudent$] where StuId not in (select StuId from (select  A.StuId,B.TeaId from [tblScore$] A left join [tblCourse$] B on  A.CourseId=B.CourseId) C where  TeaId=(select TeaId from [tblTeacher$] where TeaName="叶平"))
6查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名select StuId,StuName  from [tblStudent$] where StuId   in(select  A.StuId from  (select * from [tblScore$] where  CourseId="002") A , (select * from [tblScore$] where  CourseId="001") B where A.StuId=B.StuId and  A.Score<B.Score)
8查询没有学全所有课的同学的学号、姓名select StuId,StuName  from [tblStudent$] where StuId in (select StuId from (select StuId,StuName, 0  as CourseId from [tblStudent$] union select StuId,null as StuName,CourseId  from [tblScore$]) group by StuId having count(CourseId)<(select count(*)  from [tblCourse$]))
9查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;select StuId,StuName  from [tblStudent$] where StuId in (select distinct StuId from [tblScore$]  where CourseId  in (select CourseId  from [tblScore$] where StuId="1001"))
回复

使用道具 举报

发表于 2014-6-4 18:16 | 显示全部楼层
3
  1. SELECT B.StuId,StuName,CountCourse,SumScore
  2. FROM [tblStudent$]A
  3. RIGHT JOIN
  4.         (SELECT StuId,COUNT(CourseId) AS CountCourse,SUM(Score) AS SumScore
  5.          FROM [tblScore$]        
  6.          GROUP BY StuId)B
  7. ON A.StuId=B.StuId
复制代码
5
  1. SELECT StuId,StuName
  2. FROM [tblStudent$]
  3. WHERE StuId NOT IN
  4.         (SELECT B.StuId
  5.          FROM [tblCourse$]A, [tblScore$]B,[tblStudent$]C,[tblTeacher$]D
  6.          WHERE D.TeaId = A.TeaId
  7.                 AND A.CourseId = B.CourseId
  8.                 AND B.StuId = C.StuId AND TeaName='叶平')
复制代码
6
  1. SELECT StuId,StuName
  2. FROM [tblStudent$]
  3. WHERE StuId IN
  4.         (SELECT A.StuId FROM
  5.                 (SELECT StuId,Score
  6.                  FROM [tblScore$]
  7.                  WHERE CourseId="002")A
  8.         INNER JOIN
  9.                 (SELECT StuId,Score
  10.                  FROM [tblScore$]
  11.                  WHERE CourseId="001")B
  12.         ON A.StuId=B.StuId AND A.Score<B.Score)
复制代码
8
  1. SELECT A.StuId,StuName
  2. FROM [tblStudent$]A,[tblScore$]B  
  3. WHERE A.StuId=B.StuId
  4. GROUP BY A.StuId,StuName
  5. HAVING COUNT(StuName)<(SELECT COUNT(1) FROM [tblCourse$])
复制代码
9
  1. SELECT A.StuID,StuName
  2. FROM (SELECT DISTINCT StuId
  3.                     FROM [tblScore$]
  4.         WHERE CourseId
  5.         IN(SELECT CourseId
  6.                 FROM [tblScore$]
  7.                 WHERE StuId="1001"))A   
  8. LEFT JOIN [tblStudent$]B
  9. ON A.StuID=B.StuID
复制代码
回复

使用道具 举报

发表于 2014-6-4 22:05 | 显示全部楼层
1
  1. select t1.Stuid,t1.Stuname,t2.CountCourse,t2.TotalScore from [tblstudent$a:d]t1,(select stuid,count(*) as CountCourse,sum(score) as TotalScore from [tblscore$a:c] group by stuid)t2 where t1.stuid=t2.stuid
复制代码
2
  1. select Stuid,StuName from [tblstudent$a:d] where stuid not in (select t3.stuid from [tblstudent$a:d]t3,[tblscore$a:c]t4,(select courseid from [tblcourse$a:c]t1,[tblteacher$a:b]t2 where t1.teaid=t2.teaid and teaname="叶平")t5 where t3.stuid=t4.stuid and t4.courseid=t5.courseid group by t3.stuid)
复制代码
3
  1. select Stuid,StuName from [tblstudent$a:d] where stuid in (select t1.stuid from (select stuid,score from [tblscore$a:c] where courseid="001")t1 inner join (select stuid,score from [tblscore$a:c] where courseid="002")t2 on t1.stuid=t2.stuid and t1.score>=t2.score)
复制代码
4
  1. select Stuid,StuName from [tblstudent$a:d] where stuid not in (select stuid from [tblscore$a:c] group by stuid having count(*)=(select count(courseid) from [tblcourse$a:c]))
复制代码
5
  1. select Stuid,StuName from [tblstudent$a:d] where stuid in (select stuid from [tblscore$A:c] where courseid in (select courseid from [tblscore$a:c] where stuid="1001") group by stuid)
复制代码
回复

使用道具 举报

发表于 2014-6-5 18:32 | 显示全部楼层
本帖最后由 xdragon 于 2014-6-6 15:43 编辑

先做第一个的。。。
3
  1. select a.StuId,StuName,count(CourseId) as CountCourseId,sum(Score) as SumScore from [tblStudent$] a left join [tblScore$] b on a.StuId=b.StuId group by a.StuId,a.StuName having count(CourseId)>0
复制代码
5
  1. select StuId,StuName from [tblStudent$] where StuId not in (select a.StuId from (([tblStudent$]a right join [tblScore$]b on a.StuId=b.StuId) left join [tblCourse$]c on b.CourseId=c.CourseId) left join [tblTeacher$]d on c.TeaId=d.TeaId where TeaName='叶平')
复制代码
6

8
  1. select a.StuId,StuName from [tblStudent$] a left join [tblScore$]b on a.StuId=b.StuId group by a.StuId,StuName having count(CourseId)<(select count(*) from [tblCourse$])
复制代码
9
  1. select distinct a.StuId,StuName from [tblScore$]a left join [tblStudent$]b on a.StuId=b.StuId where CourseId in (select CourseId from [tblScore$] where StuId='1001')
复制代码
回复

使用道具 举报

发表于 2014-6-6 14:30 | 显示全部楼层
本帖最后由 天空的雨 于 2014-6-9 15:22 编辑

数据透视表中级班练习八-天空的雨答.rar (43.14 KB, 下载次数: 3)
回复

使用道具 举报

发表于 2014-6-9 22:24 | 显示全部楼层
本帖最后由 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"))
回复

使用道具 举报

发表于 2014-7-10 20:50 | 显示全部楼层
本帖最后由 jio1ye 于 2014-7-10 20:59 编辑

这个比较不难了,所以说回复的人多了一米米? 5.数据透视表中级班_练习8.rar (41.81 KB, 下载次数: 1)
回复

使用道具 举报

发表于 2014-7-18 15:11 | 显示全部楼层
结果3、
  1. SELECT T1.STUID,STUNAME,COUNT(SCORE) AS COUNTCOURSE,SUM(SCORE) AS SUMSCORE FROM([TBLSTUDENT$]T1 LEFT JOIN [TBLSCORE$]T2 ON T1.STUID=T2.STUID) GROUP BY T1.STUID,STUNAME HAVING COUNT(SCORE)>0
复制代码
结果5、
  1. select t1.StuId,StuName from([tblscore$]t1 left join [tblStudent$]t2 on t1.StuId=t2.StuId) where CourseId not in(select CourseId from [tblCourse$] where TeaId=(select TeaId from [tblTeacher$] where TeaName='叶平')) group by T1.StuId,StuName
复制代码
结果6、
  1. select t1.StuId,StuName from(select t1.StuId from(select * from [tblScore$] where CourseId='002')t1,(select * from [tblScore$] where CourseId='001')t2 where t1.StuId=t2.StuId and t1.Score<t2.Score)t3 left join [tblStudent$]t4 on t3.StuId=t4.StuId
复制代码
结果8、
  1. 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 [tblCourse$])
复制代码
结果9、
  1. select t1.StuId,StuName from [tblStudent$]t1,(select StuId from [tblScore$] where courseId in(select CourseId from [tblScore$] where StuId='1001'))t2 where t1.StuId=t2.StuId group by t1.StuId,StuName
复制代码
回复

使用道具 举报

发表于 2015-3-10 19:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 08:07 , Processed in 0.270165 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表