举例:
表名为:s_ave
表的内容:
AveAvename
1d
3e
4a
6b
5e
我们要查询 ave=6 的行号:
set @mytemp = 0
select * from (
SELECT (@mytemp:=@mytemp+1) as newid,Ave,Avename FROM s_ave
) AS A
WHERE A.Ave=6
自己试一下吧,这里 mytemp 的值就是行号
转自:http://zhidao.baidu.com/link?url=s7xymIjJkwxR1AwTPwJRrgcZN6NX3A78sC4o0QAbOtNNYIfE94Y0ITUyo2yHU6DgnU0aXrwCyF99CST8qhhbiq
create or replace procedure (ave out number,themax out number,themin varchar2)isMathmax number
Mathmin number
chinesemax number
chinesemin number
englishmax number
englishmin number
totle number
sum1 number
sum2 number
sum3 number
count1 number
begin
select Math into Mathmax from score where 1=1 order by desc
select Math into Mathmin from score where 1=1 order by asc
select chinese into chinesemin from score where 1=1 order by asc
select chinese into chinesemax from score where 1=1 order by desc
select english into englishmax from score where 1=1 order by desc
select english into englishmin from score where 1=1 order by asc
---the max
if Mathmax>chinesemax then
themax:=Mathmax
else
themax:=chinesemax
end if
if themax > englishmax then
themax:=themax
else
themax:=englishmax
end if
---the min
if Mathmin>chinesemin then
themin:=chinesemin
else
themin:=Mathmin
end if
if themin > englishmin then
themin:=englishmin
else
themin:=themin
end if
--the average
select count(1) into count1 from score
select sum(math) into sum1 from score
select sum(chinese) into sum2 from score
select sum(english) into sum3 from score
ave:=(sum1+sum2+sum3)/count1
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)