UPDATE RS_HMST
SET pay_status_cd = 'RSPAYA002'
WHERE rs_hmst_seq = :rs_hmst_seq
AND total_amt+add_amt-dc_amt - IFNULL((SELECT sum(RS_HPAY.pay_amt) FROM RS_HPAY WHERE RS_HPAY.rs_hmst_seq = :rs_hmst_seq AND RS_HPAY.in_yn='Y'),0) <= 0