Hello fellow developers, I'm trying to convert my query into eloquent code,but as I was using "CASE" commands among other commands I decided to insert the select section into a DB::raw but now I experience some syntax error or access violation:1055, here is my sql:
SELECT pa.id_budget_total,pa.name,CASE WHEN co.budget IS null THEN pa.amount ELSE pa.amount - SUM(co.budget) END AS left
FROM budget_total pa LEFT JOIN convening co ON pa.id_budget_total = co.budget_total
where pa.status = 1 GROUP BY pa.name
I kind of converted it to eloquent but when I add co.budget it tells me the error code followed by that co.budget is not group by, and yes it displays no error if I add it within the groupBy but that'd change the whole result. Here it's the eloquent code:
budget_total::select(DB::raw("pa.id_budget_total,pa.name, CASE WHEN co.budget IS null THEN pa.amount ELSE pa.amount - SUM(co.budget) END AS restante"))
->from("budget_total as pa")->leftJoin("convocatoria as co","pa.id_budget_total","=","co.id_budget_total")->where("pa.status", 1)
->groupBy("pa.id_budget_total","pa.name","pa.amount")->get();
CASEexpression.