如何在sql中的列中选择第二行的值?

I want to deduct an amount from a view balance containing columns gp_no,member_no, member_name, sum(dr) as dr. Now , when the user pays some amount say 1,50,000 then it should first deduct from first group i.e., gp_no = 1 (let say his outstanding balance in gp_no = 1 is 75,000 then it should be 1,50,000 - 80,000 so gp_no = 1 should be clear now) , if the amount still remains(70,000 in our eg) then deduct from second group i.e., gp_no = 2 and so on . Can anyone help me out please. Thanks in advance :)

create view balance as 
select instalment.gp_no , 
       instalment.member_no , 
       sum(dr) as dr, 
       list.member_name 
from instalment 
join list 
    on instalment.member_no = list.member_no 
group by instalment.gp_no

This is the PHP code

If(isset($_REQUEST['submit'])!='')
{

 $member_no = $_REQUEST['member_no'];
 $payment = $_REQUEST['payment'];

 $sql = "select gp_no,sum(dr) as dr from instalment WHERE  member_no =    '$member_no' group by gp_no" ;
 $result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
    {
        echo  "got the value " ;
     $dr = $row["dr"];

    }
}
 while ( $debited_amount !=0 )
 {
   $debited_amount = $dr - $payment ; 

     if ($debited_amount < 0 )   // when the user pays more amount as he needs to pay for gp_no = 1
     {
          // dr will be updated by dr = 0;
          // and move to next dr for subratraction i.e., dr of gp_no = 2 
     }
     elseif ($debited_amount > 0)  // when the user pays less amount as he needs to pay for gp_no = 1
     {
         // dr will be updated by dr = $debited_amount ; 
     }
     else  // when the user pays exactly the same amount as he needs to pay for gp_no = 1
     {
         // dr will be updated by dr = 0;
     }

}