Oct 20, 2018
0
Level 2
Divide a column by another column created from Sub query
I've this query -
$employees = Employee::where('user_id', $user->id)->withCount([
'answers as questions_received' => function ($query) use($date) {
$query->where('created_at', '>=', $date);
},
'answers as correct' => function ($query) use($date) {
$query->where('correct', 1)->where('created_at', '>=', $date);
}
]);
$employees = $employees
->orderBy('answered', 'desc')
->orderBy('correct', 'desc')
->get();
I want to do something like this -
((questions_received/correct) * 100) as percentage
But don't understand how to do it. Please help :)
Thank you
Please or to participate in this conversation.