在SQL Server中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,

在SQLServer中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,选手的得分最后为余下分数的平均分。求,急!!!... 在SQL Server中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,选手的得分最后为余下分数的平均分。求,急!!! 展开
 我来答
badkano
推荐于2016-01-21 · 知道合伙人体育行家
badkano
知道合伙人体育行家
采纳数:144779 获赞数:885352
团长

向TA提问 私信TA
展开全部

创建:

create proc p_avg_score
(@score1 decimal(4,2),
@score2 decimal(4,2),
@score3 decimal(4,2),
@score4 decimal(4,2),
@score5 decimal(4,2),
@score6 decimal(4,2),
@score7 decimal(4,2),
@score8 decimal(4,2),
@score9 decimal(4,2),
@score10 decimal(4,2))--定义10个输入参数
as
declare @avg_score decimal(4,2) --定义平均值
declare @max_score decimal(4,2) --定义最高分数
declare @min_score decimal(4,2) --定义最低分数
select @max_score=MAX(score) from 
(select @score1 as score 
union all
select @score2 
union all
select @score3 
union all
select @score4 
union all
select @score5 
union all
select @score6 
union all
select @score7
union all
select @score8 
union all
select @score9 
union all
select @score10) t  --获取分数中的最高分

select @min_score=min(score) from
(select @score1 as score 
union all
select @score2 
union all
select @score3 
union all
select @score4 
union all
select @score5 
union all
select @score6 
union all
select @score7
union all
select @score8 
union all
select @score9 
union all
select @score10) t  --获取分数中的最低分

select @avg_score=round((SUM(score)-@min_score-@max_score+0.00)/8,2) from
(select @score1 as score 
union all
select @score2 
union all
select @score3 
union all
select @score4 
union all
select @score5 
union all
select @score6 
union all
select @score7
union all
select @score8 
union all
select @score9 
union all
select @score10) t where score not in (@min_score,@max_score) --去掉一个最高分和一个最低分后的平均分
print @avg_score --打印成绩

执行:

exec p_avg_score 1,2,3,4,5,6,7,8,9,4

其中1,2,3,4,5,6,7,8,9,4为输入的10个成绩

执行结果:

追答
这个去掉:where score not in (@min_score,@max_score)
追问
但是能不能用while的方式找出最大值,最小值啊,然后再总分减去,好吗?能给我一个这个答案嘛
jelvis
2015-12-29 · TA获得超过5631个赞
知道大有可为答主
回答量:2480
采纳率:62%
帮助的人:784万
展开全部

只用SQL Server?输出倒还好办?输入呢?或许可以用XML文件的方式保存输入数据,即选手和打分。

  1. 创建一个存储过程,参数是一个长字符串,用于录入xml

  2. 然后在存储过程中打开这个xml,存储到临时表里(OPENXML)

  3. 针对每个选手的打分去掉最高和最低

  4. 计算平均分(group by ,avg等 )

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式