how to fetch 1 by 1 record from table in db2
sno acco_no amount
1 50001 5000
2 50002 4000
3 50001 2500
4 50002 3100
5 50002 3400
6 50001 1500
in which i want to take 50001's last 2 rec开发者_运维问答ords one by one.
ie is result'd be :
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
pls help me anyone
Use this to get only the last 2 records
select *
from tbl
where acco_no = 50001
order by sno desc
FETCH FIRST 2 ROWS ONLY;
Then in your code, store the first record into var 1 and the 2nd into var 2.
精彩评论