How to write query sql on laravel

- 1 answer

Ad

I'm new to Laravel 4. I have Query Sql Like this

SELECT at.test_id, MAX(at.result), COUNT(status_assessment_id='2') FROM recruitment_process a LEFT JOIN recruitment_result at ON a.id = at.recruitment_id GROUP BY test_id

I do not know how can I write this on Laravel 4?

Ad

Answer

Ad

I haven't checked but you can try this

DB::table('recruitment_process a')
    ->select('at.test_id', DB::raw('MAX(at.result)'), DB::raw('COUNT(status_assessment_id="2")'))
    ->leftJoin('recruitment_result at', 'a.id', '=', 'at.recruitment_id')
    ->groupBy('at.test_id')
    ->get();

More details here https://laravel.com/docs/4.2/queries

Ad
source: stackoverflow.com
Ad