## Forum

# Eloquent Groupby with Rollup

How do I use the mysql rollup feature with laravel eloquent?

I did try a few but not able to get the rollup result. Below is my code which i have test.

```
return $query->where('eventid', $value)->select('rhq', DB::raw('SUM(CASE WHEN division = "MD" THEN 1 End) as MD,
SUM(CASE WHEN division = "WD" THEN 1 End) as WD, SUM(CASE WHEN division = "YM" THEN 1 End) as YM,
SUM(CASE WHEN division = "YW" THEN 1 End) as YW, SUM(CASE WHEN division = "PD" THEN 1 End) as PD,
SUM(CASE WHEN division = "UN" THEN 1 End) as UnKnown, Count(name) as Total,
SUM(CASE WHEN position = "NF" THEN 1 End) as NewFriend'))->groupBy(DB::raw('rhq with rollup'));
```

Want to reply to this thread?

Login with github.
## chankl78

Just to confirm that the above code is working. Cos of my screwed in some of the settings for datatable, that's y it does not display out.