MyCode
$datas = DB::table('patrol_gate_surveillance_transactions as a')
->leftJoin('client_locations as b','a.client_location_id', 'b.id')
->leftJoin('clients as c', 'b.client_id', 'c.id')
->select('a.client_location_id as location_id', 'b.name as location_name', 'c.name as client_name',
DB::raw('SUM(CASE WHEN a.type = 1 THEN employee_qty ELSE 0 END) as e_qty_in'),
DB::raw('SUM(CASE WHEN a.type = 2 THEN employee_qty ELSE 0 END) as e_qty_out')
)
->groupBy('location_id', 'location_name', 'client_name')
->get();
#MyProblem
I can't add created_at to the SELECT because it will interfere with the GROUPING I've created.
myTable
