0

Hey guys Im new to laravel. I have this table

enter image description here

How will i able to fetch count of 'is_correct' column for each subject?

Thanks guys!

1 Answer 1

1

Try this, replace the Model with your eloquent model name

Model::select(
'subject_id',
 Illuminate\Support\Facades\DB::raw("COUNT(is_correct) as count")
)
->groupBy('subject_id')
->get();
Sign up to request clarification or add additional context in comments.

4 Comments

hey man tried this but no luck it gives me a database error 1055 thanks!
Can you share the error message? and the code you tried?
I've edited the answer. Please check whether it's working
Hey dude @Kenath. I think it works now and had a syntax error. This is a great help thanks a lot. Anyway I also find this very similar if someone need it. similar_scenario

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.