Laravel 4 普通查询中的laravel查询生成器

Laravel 4 普通查询中的laravel查询生成器,laravel-4,Laravel 4,这是普通查询。是否更改为laravel查询?。 我试过了 我无法比较->where('sum(payment\u transactions.amount)',!=',DB::raw('bill\u det.amount\u payment')) 我使用的是这样的->whereRaw('bill\u det.amount\u paid!=sum(payment\u transactions.amount) {“error”:{“type”:“illumb\Database\QueryExcepti

这是普通查询。是否更改为laravel查询?。 我试过了

我无法比较
->where('sum(payment\u transactions.amount)',!=',DB::raw('bill\u det.amount\u payment'))

我使用的是这样的
->whereRaw('bill\u det.amount\u paid!=sum(payment\u transactions.amount)

{“error”:{“type”:“illumb\Database\QueryException”,“message”:“SQLSTATE[HY000]:一般错误:1111将组函数(SQL:select count(*)用作来自(选择“1”作为行计数,从
bill\u det
left join
payment\u transactions
on
bill\u det
=
payment\u transactions
中选择
payment\u transactions
状态=成功和bill\u det.amount\u支付!=金额(payment\u transactions.amount)分组依据
bill\u det
bill\u no
订单依据
bill\u det
bill\u no
desc)计数行表)

将此转换为laravel查询后::

DB::select(DB::raw( 'SELECT a.bill_no, a.account_id, a.bill_date, a.amount_paid,
                            b.transaction_code,b.amount from  bill_det a left join
                            (select bill_no, transaction_code, sum(amount) as amount from payment_transactions 
                            where status = "success" group by bill_no ) b
                            on a.bill_no = b.bill_no where a.amount_paid != b.amount order by b.bill_no'));

你试过什么了吗?我试过了。问题是我无法比较需要使用whereRaw来比较sum()结果的总和。我使用whereRaw,但它给出了如上所述的错误。我认为你应该使用“having”语句而不是“where”语句
$bill=DB::table('bill_det')->leftJoin('payment_transactions', 'bill_det.bill_no', '=', 'payment_transactions.bill_no')
                                ->select('bill_det.bill_no','bill_det.account_id','bill_det.bill_date','bill_det.amount_paid',
                                'payment_transactions.transaction_code',DB::raw('sum(payment_transactions.amount) as amount'))
                                ->where('payment_transactions.status','=','success')
                                ->where('sum(payment_transactions.amount)','!=',DB::raw('bill_det.amount_paid'))
                                ->groupBy('bill_det.bill_no')
                                ->orderBy('bill_det.bill_no','desc');
DB::select(DB::raw( 'SELECT a.bill_no, a.account_id, a.bill_date, a.amount_paid,
                            b.transaction_code,b.amount from  bill_det a left join
                            (select bill_no, transaction_code, sum(amount) as amount from payment_transactions 
                            where status = "success" group by bill_no ) b
                            on a.bill_no = b.bill_no where a.amount_paid != b.amount order by b.bill_no'));
$query = \Illuminate\Support\Facades\DB::table('bill_det')
            ->select('a.bill_no', 'a.account_id', 'a.bill_date', 'a.amount_paid', 'b.transaction_code', 'b.amount')
            ->leftJoin(DB::raw('(select bill_no, transaction_code, sum(amount) as amount from payment_transactions 
                            where status = "success" group by bill_no) b'), function($join) {
                $join->on('a.bill_no', '=', 'b.bill_no');
            })
            ->where('a.amount_paid','<>', 'b.amount')
             ->orderBy('b.bill_no')
            ->get();
$query->whereRaw(DB::raw('(your expression!!)'));