mardi 27 septembre 2016

Convert SQL query SELECT SUM into laravel 5

I have this SQL query

select sum(repayment_borrower.settle_amount+ repayment_borrower.settle_interest + repayment_borrower.settle_penalty) as "Total Default"
     FROM repayment_borrower,loans,loan_offer, lender
     WHERE repayment_borrower.loans_id = loans.id
     AND loan_offer.loan_id = loans.ID
     AND loans.lnsts <> "999"
     AND LOANS.lnsts = "810"
     AND loan_offer.lender_id = lender.id
     and lender.user_id = "3" 

This code work when I apply in sql phpmyadmin. But, when I convert at laravel like this

$count_badloans        =  DB::select( DB::raw("SELECT sum(repayment_borrower.settle_amount+ repayment_borrower.settle_interest + repayment_borrower.settle_penalty) as Total Default
                                                    FROM repayment_borrower,loans,loan_offer, lender
                                                    WHERE repayment_borrower.loans_id = loans.id
                                                    AND loan_offer.loan_id = loans.id
                                                    AND loans.lnsts <> 999
                                                    AND loans.lnsts = 810
                                                    AND loan_offer.lender_id = lender.id
                                                    and lender.user_id = $userId ") );

an error occurred like this

error

am I wrong to apply the query to the laravel? Please help.....

thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire