mysql统计-关于学生成绩
来源:互联网 发布:java程序员认证培训 编辑:程序博客网 时间:2024/05/01 00:02
<span style="color: rgb(255, 0, 0); font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">注意前5个问题使用张三和李四两个字段</span>
1.计算每个人的总成绩并排名(要求显示字段:姓名,总成绩)
SELECT name,SUM(score)from stuscoreGROUP BY `name`ORDER BY SUM(score) ASC
2.
SELECT stuid,`name`,SUM(score)FROM stuscoreGROUP BY `name`ORDER BY SUM(score)
stuid
name
SUM(score)1张三2392李四240
3.
写法1
SELECT stuid,`name`,`subject`,max(score)FROM stuscoregroup by stuid
写法2:
SELECT t1.stuid,t1.`name`,t1.`subject`,t1.scoreFROM stuscore t1,(SELECT `stuid`,MAX(score) AS maxscore FROM stuscore GROUP BY `stuid`) t2where t1.stuid=t2.stuid and t1.score=t2.maxscorestuidnamesubjectscore1张三数学892李四数学90
4.
SELECT stuid,`name`,AVG(score)FROM stuscoregroup by stuidstuidname
AVG(score)1张三79.66672李四80.0000
5.
方法一:
SELECT stuid,`name`,`subject`,max(score)FROM stuscore GROUP BY `subject`
方法二:
SELECT t1.stuid,t1.`name`,t1.`subject`,t2.maxscoreFROM stuscore t1,(SELECT `subject`,MAX(score)as maxscore FROM stuscore GROUP BY `subject`)t2WHERE t1.`subject`=t2.`subject` and t1.score=t2.maxscorestuidnamesubjectmaxscore1张三语文802李四数学902李四英语80
从问题6开始增加王五字段
6.
select stuid,`name`,SUM(score)as sumscorefrom stuscore GROUP BY `name`order by sumscore DESCLIMIT 2stuidnamesumscore3王五2682李四240
7.列出数学成绩的排名
select `name`,`subject`,scorefrom stuscorewhere `subject`="数学"ORDER BY score DESC8.求出李四的数学成绩的排名
9.统计学科成绩及格,良,优的个数
select subject, (select count(*) from stuscore where score<60 and subject=t1.subject) as 不及格,(select count(*) from stuscore where score between 60 and 80 and subject=t1.subject) as 良,(select count(*) from stuscore where score >80 and subject=t1.subject) as 优from stuscore t1 <span style="font-family: 宋体;">group by subject</span>subject及格良优数学003英语021语文02110.学号
</pre><pre name="code" class="sql">select stuid as 学号,name as 姓名,sum(case when subject='语文' then score else 0 end) as 语文,sum(case when subject='数学' then score else 0 end) as 数学,sum(case when subject='英语' then score else 0 end) as 英语,sum(score) as 总分,(sum(score)/count(*)) as 平均分from stuscoregroup by stuid,name
2 0
- mysql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- 【转】 sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql统计-关于学生成绩
- sql 统计-关于学生成绩
- 【转】 sql统计-关于学生成绩(答案)
- 学生成绩统计器
- 学生成绩统计
- 学生成绩统计
- 【转】大数据量分页查询方法
- 词语辨析
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- MIT自然语言处理第三讲:概率语言模型(第四、五、六部分)
- 手把手教你如何加入到github的开源世界!
- mysql统计-关于学生成绩
- C/S通信模型与B/S通信模型介绍
- C++中引用、指针,传值的联系和区别
- 使用navicat建立与服务器的远程mysql连接
- 无线键鼠接收器丢了怎么办
- 初学MCMC(Markov Chain Monte Carlo)
- IOS开发-初识CoreData
- 从sqlcommandbuilder引出的小想法
- 关于java 值传递