jeudi 28 juillet 2016

Nested Query in Laravel 5.2 Query Builder Pulling MAX date

I'm trying to pulling a group of users who have not made a transaction since a specified date.

This is my query:

    $notActive = DB::table('transactions')
    ->join('users','transaction.user_id', '=', 'users.user_id' )
    ->select(DB::raw('users.user_id, users.name, max(transaction.last_posted_date) AS lastDate'))
    ->groupBy('users.user_id')
    ->where('lastDate', '<', ''.$not.'');

    return Datatables::of($notActive)
    ->make(true);

$not is the date value pulled in. This produces an ajax data-tables error. I've tried this multiple ways including putting a select statement for the max date in the where clause but it keeps throwing up errors. Is there a better way to query this data that I want? Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire