Reputation: 1619
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?
Upvotes: 2
Views: 97
Reputation: 5166
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
Upvotes: 2
Reputation: 2869
The way I would do it would be:
DB::table('recruitment_process')
->select(
array('recruitment_result.test_id',
DB::raw('COUNT(status_assessment_id='2') as mycount'),
DB::raw('MAX(recruitment_result.result) as maxvalue')))
->left_join('recruitment_result', 'recruitment_process.id', '=', 'recruitment_result.recruitment_id')
->group_by('test_id')
->get();
Not sure if there is any faster or more effective way.
Upvotes: 0