我想在存储过程中实现以下功能:取01号仓库上上上个月的出货量,(不是每个月都出货,所以不能用当前月减3来求)
我是这么写的:
select tb1.huo
into :llhuo
from (select rownum rn,huo from ku where kuid=01 order by year desc,month desc) tb1
where rn=3
但是,求出来的值不对,因为rownum是没有排序以前的行号
请问这个功能如何实现?!~
我是这么写的:
select tb1.huo
into :llhuo
from (select rownum rn,huo from ku where kuid=01 order by year desc,month desc) tb1
where rn=3
但是,求出来的值不对,因为rownum是没有排序以前的行号
请问这个功能如何实现?!~
into :llhuo
from (select row_number()over(order by year desc,month desc) rn,huo from ku where kuid=01 ) tb1
where rn=3
from (
select rownum as rn, tb1.huo
from
(
select huo
from ku
where kuid=01
order by year desc,month desc
) tb1
)tb2
where tb2.rn = 3