首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

在成绩治理存储过程中,最低分数、最高分数的计算不允许使用系统函数(包括

2012-09-10 
在成绩管理存储过程中,最低分数、最高分数的计算不允许使用系统函数(包括在成绩管理存储过程中,最低分数、最

在成绩管理存储过程中,最低分数、最高分数的计算不允许使用系统函数(包括
在成绩管理存储过程中,最低分数、最高分数的计算不允许使用系统函数(包括

max、min),通过为每一个课程建立临时表的方式实现该功能。

[解决办法]
难道要用冒泡排序 求最大的????
[解决办法]
不理解楼主的意思,存储过程中可以使用min 和max 呀
[解决办法]
存储过程中可以使用min 和max

每一个课程建立临时表的方式实现最低分数、最高分数的计算?
[解决办法]

SQL code
declare @temp table(    score int)insert into @temp(score) values(100);insert into @temp(score) values(85);insert into @temp(score) values(50);insert into @temp(score) values(92);insert into @temp(score) values(36);insert into @temp(score) values(89);--MAX VALUEWITH MaxV AS(    SELECT score FROM @temp AS T    WHERE NOT EXISTS (SELECT * FROM @temp WHERE score > T.score)),MinV AS(    SELECT score FROM @temp AS T    WHERE NOT EXISTS (SELECT * FROM @temp WHERE score < T.score))SELECT     X.score AS MaxValue,    I.score AS MinValueFROM MaxV AS X,MinV AS IMaxValue    MinValue----------- -----------100         36(1 row(s) affected)
[解决办法]
SQL code
create table #t([studentID] int,[score] int)insert #tselect 1,72 union allselect 2,67 union allselect 3,54 union allselect 4,90 union allselect 5,53 union allselect 6,79 union allselect 7,88select(select top 1 [score] from #t order by [score] desc) as 最高分,(select top 1 [score] from #t order by [score]) as 最低分drop table #t/*最高分         最低分----------- -----------90          53*/
[解决办法]
不用max,min,那就用group by+order by?
[解决办法]
SQL code
if object_id('tab') is  not nulldrop table tabgocreate table tab([studentID] int,[score] int)insert tab select 1,72 union allselect 2,67 union allselect 3,54 union allselect 4,90 union allselect 5,53 union allselect 6,79 union allselect 7,88select(select top 1 [score] from tab order by [score] desc group by 课程) as 最高分,(select top 1 [score] from tab order by [score] group by 课程) as 最低分into #tab_课程 from tab select 最高分,最低分 from #tab_课程--drop table tab--drop table #tab_课程1 

热点排行