在SQL Server中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,
在SQLServer中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,选手的得分最后为余下分数的平均分。求,急!!!...
在SQL Server中,编写竞赛用评分程序,由10个评委给选手打分,去掉一个最高分和一个最低分,选手的得分最后为余下分数的平均分。求,急!!!
展开
2个回答
展开全部
创建:
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的方式找出最大值,最小值啊,然后再总分减去,好吗?能给我一个这个答案嘛
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询