2011-03-15 70 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

相關問題