2011-03-15 52 views
0
sno acco_no amount 

1 50001  5000 
2 50002  4000 
3 50001  2500 
4 50002  3100 
5 50002  3400 
6 50001  1500 

其中我想50001的最后2条记录一个接一个。如何从db2中的表中取1 1记录

即是result'd为:

sno acco_no amount 
6 50001 1500-----> i want to move this record to variable1 
3 50001 2500-----> i want to move this record to variable2 

请帮助我的人

回答

0

使用此只得到了最后2个记录

select * 
from tbl 
where acco_no = 50001 
order by sno desc 
FETCH FIRST 2 ROWS ONLY; 
在你的代码

然后,存储第一次记录到变量1中,第二次记录到变量2中。

+0

我想取1 1 oly – jkk 2011-03-15 11:14:57

+0

@ user659907:你能澄清一下你的意思吗?你是否希望两行都在一行中,如(sno,acco_no,amount,sno2,acco_no2,amount2)? – Leons 2011-03-15 16:33:44