Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

chankl78 said:

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'));

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

chankl78 chankl78 Joined 2 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.