我需要将此查询转换为laravel查询。我已经阅读了文档,但是对于我来说仍然太混乱且难以完成任务。我在Google上进行了搜索,但找不到任何解决方案。
SELECT u.name ,
((SUM(tot_expenseamount)/ SUM(tot_noofmeal))*tot_noofmeal) as total_Cost,
IFNULL(t.tot_expenseamount,0) AS tot_expense_amount ,
IFNULL(n.tot_noofmeal,0) AS tot_no_of_meal
FROM users u
LEFT JOIN (
SELECT e.user_id , SUM(e.expenseamount) AS tot_expenseamount
FROM expenses e
WHERE e.expensedate >= '2019-04-01' + INTERVAL 0 MONTH AND e.expensedate < '2019-04-01' + INTERVAL 1 MONTH
GROUP BY e.user_id ) t ON t.user_id = u.id
LEFT JOIN (
SELECT m.user_id , SUM(m.noofmeal) AS tot_noofmeal
FROM meals m
WHERE m.mealdate >= '2019-04-01' + INTERVAL 0 MONTH AND
m.mealdate < '2019-04-01' + INTERVAL 1 MONTH
GROUP BY m.user_id ) n ON n.user_id = u.id
GROUP BY u.name
ORDER BY u.name