2

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?

2
  • Are you using Laravel 4.2? Commented Dec 27, 2015 at 6:20
  • hy ARIF MAHMUD RANA yes I'm using laravel 4.2 Commented Dec 27, 2015 at 6:23

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

matt yah meybe it's not effective way. but I'm appreciate you have answer I will try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.