Laravel Eloquent Query Issue with Sum

198 Views Asked by At

I'm a newbie in Laravel and I tried to connect two tables with SUM of one column along with other columns, But it's returned an error and I don't know how to fix that.

$sinv =DB::table('salesinvoices')
           ->leftJoin('customers','customers.id','=','salesinvoices.customer')
            ->select(DB::raw('sum((salesinvoices.grand_total)-(salesinvoices.isslnrtn_amt)) as sumgrand'),'customers.short_name')
            ->where('salesinvoices.is_deleted','0')
            ->where('salesinvoices.is_returned','!=','1')
            ->where('salesinvoices.paidstatus','!=','1')
            ->groupBy('salesinvoices.customer_id')
            ->get();

If I remove the customers.short_name it will return the answer And this is the error:

Syntax error or access violation: 1055 'agrimerptow.customers.short_name' isn't in GROUP BY"

0

There are 0 best solutions below