Excel精英培训网

 找回密码
 注册
查看: 9781|回复: 20

数据透视表中级班练习三

[复制链接]
发表于 2014-5-13 21:38 | 显示全部楼层 |阅读模式
本帖最后由 JLxiangwei 于 2014-5-27 12:47 编辑

SQL练习题1 .rar (43.49 KB, 下载次数: 203)

评分

参与人数 4 +54 金币 +20 收起 理由
jio1ye + 6 很给力!
zx_wl + 10 赞一个!
云影 + 18 很给力!
9lee + 20 + 20 赞一个!

查看全部评分

发表于 2014-5-13 22:39 | 显示全部楼层
本帖最后由 云影 于 2014-5-14 18:17 编辑

多谢老师指点,已修改{:011:}
练习2
  1. SELECT count(*) as Mrli_Count  FROM [tblTeacher$] where teaname like "李%"
复制代码
练习13
  1. select Courseid as 课程ID,max(Score) AS 最高分,min(Score) AS 最低分 from[tblScore$] group by Courseid
复制代码
练习19
  1. select Stusex,count(*) AS StuSex_count from[tblStudent$] GROUP BY Stusex
复制代码
练习20
  1. select StuName,COUNT(*) as Stu_Count from[tblStudent$] group by StuName  having COUNT(*)>1
复制代码
练习21
  1. select Courseid,ROUND(Avg(score),2) as Score_Avg from [tblScore$] group by CourseId order by Avg(score) ASC, Courseid DESC
复制代码
练习32
  1. select Stuid from[tblscore$] group by Stuid having count(*)>1
复制代码
练习34
  1. select Stuid,Courseid,Score from[tblscore$] where Courseid ='004'and Score <60 order by Stuid desc, Score desc
复制代码

点评

其他正确!  发表于 2014-5-14 16:36
练习中的COUNT(...)可用COUNT(*)代替。  发表于 2014-5-14 16:33
练习21和34少了排序。  发表于 2014-5-14 16:32

评分

参与人数 1金币 +16 收起 理由
JLxiangwei + 16 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-5-14 11:08 | 显示全部楼层
2
  1. SELECT StuId,ROUND(AVG(Score),2) AS AvgScore FROM [tblScore$] GROUP BY StuId HAVING AVG(Score)>60
复制代码
4
  1. SELECT COUNT(TeaName) AS Mrli_Count FROM [tblTeacher$] WHERE TeaName LIKE '李%'
复制代码
13
  1. SELECT CourseId AS 课程ID,MAX(Score) AS 最高分,MIN(Score) AS 最低分 FROM [tblScore$] GROUP BY CourseId
复制代码
19
  1. SELECT Stusex AS StuSex,COUNT(Stusex) AS StuSex_count FROM [tblStudent$] GROUP BY Stusex
复制代码
20
  1. SELECT StuName,COUNT(StuName) AS Stu_Count FROM [tblStudent$] GROUP BY StuName HAVING COUNT(StuName)>2
复制代码
21
  1. SELECT CourseId,FORMAT(AVG(Score),"#.00") AS Score_Avg FROM [tblScore$] GROUP BY CourseId ORDER BY AVG(Score),CourseId DESC
复制代码
32
  1. SELECT StuId FROM [tblScore$] GROUP BY StuId HAVING COUNT(CourseId)>1
复制代码
34
  1. SELECT StuId,CourseId,Score FROM [tblScore$] WHERE CourseId="004" AND Score<60 ORDER BY Score DESC
复制代码

点评

其他正确!  发表于 2014-5-14 16:36
练习20中的条件是至少二门课,我理解是〉1.  发表于 2014-5-14 16:36

评分

参与人数 1 +16 收起 理由
JLxiangwei + 16

查看全部评分

回复

使用道具 举报

发表于 2014-5-14 11:13 | 显示全部楼层
本帖最后由 天空的雨 于 2014-6-4 11:04 编辑

SQL练习题1 -天空的雨答.zip (42.03 KB, 下载次数: 14)

点评

超多的解题方法,思路很活,向你学习!  发表于 2014-5-14 16:48

评分

参与人数 1 +22 收起 理由
JLxiangwei + 22 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-5-14 21:40 | 显示全部楼层
2.
  1. select * from (select StuId,avg(Score) as AvgScore from [tblScore$] group by stuid) where avgscore>60
复制代码
4.
  1. select count(*) as li_count from [tblteacher$] where left(teaname,1)="李"
复制代码
13.
  1. select CourseId,max(score) as 最高分,min(score) as 最低分 from [tblscore$] group by courseid
复制代码
19.
  1. select StuSex,count(*) as Sex_Count from [tblstudent$] group by stusex
复制代码
20.
  1. select * from (select stuname,count(*) as name_count from[tblstudent$] group by stuname) where name_count>1
复制代码
21.
  1. select CourseId,avg(score) as AvgScore from [tblscore$] group by courseid order by avg(score) ,courseid desc
复制代码
32.
  1. select StuId from (select stuid,count(*) as course_count from [tblscore$] group by stuid) where course_count>=2
复制代码
34.
  1. select StuId,CourseID,Score from [tblscore$] where Courseid="004" and score < 60 order by score desc
复制代码

点评

全部正确! 不用子查询也能实现,试一试。  发表于 2014-5-15 08:48

评分

参与人数 1 +16 收起 理由
JLxiangwei + 16

查看全部评分

回复

使用道具 举报

发表于 2014-5-15 12:41 | 显示全部楼层
  1. SELECT * FROM (SELECT StuId,AVG(Score) AS AvgScore FROM [tblScore$] GROUP BY StuId) WHERE AvgScore>60
  2. SELECT COUNT(TeaName) AS 个数 FROM [tblTeacher$] WHERE LEFT(TeaName,1)='李'
  3. SELECT CourseId AS 课程ID,MAX(Score) AS 最高分,MIN(Score) AS 最低分 FROM [tblScore$] GROUP BY CourseId
  4. SELECT Stusex,COUNT(Stusex) AS StuSex_count FROM [tblStudent$] GROUP BY Stusex ORDER BY StuSex DESC
  5. SELECT StuName,Stu_Count FROM (SELECT StuName,COUNT(StuName) AS Stu_Count FROM [tblStudent$] GROUP BY StuName) WHERE Stu_Count>1
  6. SELECT CourseId,FORMAT(AVG(Score),"0.00") AS Score_Avg FROM [tblScore$] GROUP BY CourseId ORDER BY AVG(Score),CourseId DESC
  7. SELECT StuId FROM (SELECT StuId,COUNT(CourseId) AS a FROM [tblScore$] GROUP BY StuId) WHERE a>=2
  8. SELECT StuId,CourseId,Score FROM [tblScore$] WHERE CourseId='004' AND Score<60 ORDER BY Score DESC
复制代码
这个。感觉绕弯路了,麻烦老师看看了

点评

全部正确!不用子查询也能实现,试一试。  发表于 2014-5-16 14:32

评分

参与人数 1金币 +16 收起 理由
JLxiangwei + 16

查看全部评分

回复

使用道具 举报

发表于 2014-5-15 13:45 | 显示全部楼层
结果2、
  1. select StuId,round(sum(score)/count(stuid),2) as AvgSoure from [tblScore$] group by stuid having sum(score)/count(stuid)>60
复制代码
结果4、
  1. select count(TeaName) as Mrli_Count from [tblTeacher$] group by TeaName having left(TeaName,1)="李"
复制代码
结果13、
  1. select CourseId as 课程ID,max(Score) as 最高分,min( Score) as 最低分 from [tblScore$] group by CourseId
复制代码
结果19、
  1. select Stusex,count(StuName) as StuSex_count from [tblStudent$] group by Stusex
复制代码
结果20、
  1. select StuName,count(Stuage) as Stu_Count from [tblStudent$] group by StuName having count(Stuage)>1
复制代码
结果21、
  1. select CourseId,format(Avg(Score),"0.00") as Score_Avg from [tblScore$] group by CourseId order by Avg(Score)
复制代码
结果32
  1. select iif(count(StuID)>1,StuId,null) as StuId from [tblScore$] group by StuId having iif(count(StuID)>1,StuId,null) <> null
复制代码

点评

21题少了一个排序条件。34题漏做了。  发表于 2014-5-16 14:39
第4题不需要GROUP BY  发表于 2014-5-16 14:35
求平均值可以用函数AVG.  发表于 2014-5-16 14:33

评分

参与人数 1金币 +11 收起 理由
JLxiangwei + 11

查看全部评分

回复

使用道具 举报

发表于 2014-5-15 20:40 | 显示全部楼层
希望向老师帮忙看看写的是否正确,另上课可以旁听不?
2、SELECT STUID,AVG(SCORE) AS MEAN FROM [tblScore$] GROUP BY STUID
4、SELECT COUNT(TEANAME) AS QTY FROM [tblTeacher$] WHERE TEANAME LIKE "李%" GROUP BY TEANAME
13、SELECT CourseId, MIN(Score) AS LOW,MAX(Score) AS HIG FROM [tblScore$] GROUP BY CourseId
19、SELECT Stusex,COUNT(*) AS QTY FROM [tblStudent$] GROUP BY Stusex
20、SELECT StuName,COUNT(*) AS QTY FROM [tblStudent$] GROUP BY StuName
21、SELECT CourseId,AVG(SCORE) AS MEAN FROM [tblScore$] GROUP BY CourseId  ORDER BY AVG(SCORE),CourseId DESC
32、SELECT StuId, COUNT(CourseId) FROM [tblScore$] GROUP BY StuId having COUNT(CourseId)>1
34、SELECT StuId,CourseId,Score FROM [tblScore$] where CourseId="004"  and  Score < 60 ORDER BY Score DESC

点评

2和20题少了条件。  发表于 2014-5-16 14:43

评分

参与人数 1金币 +14 收起 理由
JLxiangwei + 14

查看全部评分

回复

使用道具 举报

发表于 2014-5-15 21:38 | 显示全部楼层
交作业:
第一题:select stuid,round(avg(score),2) as avgsoure from [tblscore$] group by stuid having avg(score)>60
第二题:select count(*) as Mrli_count from [tblteacher$] where teaname like "李%"
第三题:select courseid as 课程ID, max(score) as 最高分,min(score) as 最低分 from [tblscore$] group by courseid
第四题:select stusex, count(*) as stusex_count from [tblstudent$] group by stusex
第五题:select stuname,count(stuname) as stuname_count from [tblstudent$] group by stuname having count(stuname)>1
第六题:select CourseID, format(Avg(score),"0.00") as Score_Avg from [tblscore$] group by courseid order by Avg(score),CourseID desc
每七题:select StuId from [tblscore$] group by stuid having count(stuid)>1
第八题:select StuId, CourseId, Score from [tblscore$] where CourseId="004" and Score<60 order by Score desc

点评

全部正确!  发表于 2014-5-16 14:45

评分

参与人数 1金币 +16 收起 理由
JLxiangwei + 16

查看全部评分

回复

使用道具 举报

发表于 2014-5-15 22:16 | 显示全部楼层
本帖最后由 午夜洗衣机 于 2014-5-15 22:31 编辑

向老师,怎么每一题都没有子查询或者联合查询的?
交作业:
  1. 2        select StuId,avg(Score) as AvgScore from [tblScore$] group by StuId having avg(Score)>60
  2. 4        select count(TeaName) as Mrli_count from [tblTeacher$] where TeaName like "李%"
  3. 13        select CourseID as 课程,Max(Score) as 最高分,min(Score) as 最低分 from [tblScore$] group by CourseID
  4. 19        select Stusex,count(Stusex) as StuSex_count from [tblStudent$] group by Stusex
  5. 20        select StuName,count(StuName) as Stu_Count from [tblStudent$] group by StuName having count(StuName&Stusex)>1
  6. 21        select CourseId,Avg(Score) as Score_Avg from [tblScore$] group by CourseId order by Avg(Score),CourseId desc
  7. 32        select StuId from [tblScore$] group by StuId having count(StuId&CourseId)>1
  8. 34        select StuId,CourseId,Score from [tblScore$] where CourseId="004" and Score<60 order by Score desc
复制代码
第32题我自己加了一个子查询,查询至少选修两门课程的学生学号和姓名:
  1. select StuId,StuName from [tblStudent$] where StuId in(select StuId from [tblScore$] group by StuId having count(StuId&CourseId)>1) group by StuId,StuName
复制代码

点评

全部正确!  发表于 2014-5-16 14:48

评分

参与人数 1金币 +16 收起 理由
JLxiangwei + 16

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 18:52 , Processed in 0.664293 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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