php - Two sub select query inside a where condition in laravel5? -
i want compare 2 select query inside condition of query in laravel5,
the where
condition of query in laravel given below,but not wokring.
ie,select invoice (select query1) == (select query2)
.
$invoice->orwhere(function($query) { $query->where('invoices.status', '=', invoicestatusconstant::sent) ->where('invoices.due_date', '<', carbon::today()->todatestring()) ->where(db::raw('(select round(sum(invoice_items.quantity*invoice_items.rate), 2) invoice_items'), '=', db::raw("(select sum(payments.amount) payments ")); });
how can solve issue?
db::raw won't give value. it's way create expression. if wanna way, should use:
db::select(db::raw("(select sum(payments.amount) payments"))
but give array. so, i'd following:
db::select(db::raw("(select sum(payments.amount) pay payments"))[0]->pay
or easier
db::select("(select sum(payments.amount) pay payments")[0]->pay
Comments
Post a Comment