[email protected]
3 years ago
908
8
Laravel

getting monthly sum for specific year

Posted 3 years ago by [email protected]

I have a table with date columns and revenue column, and there is entry for every single day, I'm trying to get total by month for each year, mainly current year and past year, how can i do this? i have googled for past two days but can't find any solution.

$rev = DB::table(table name)
                ->groupBy('YEAR')->get([
                            DB::raw('YEAR(date) as year'),
                            DB::raw('MONTHNAME(date) as month'),
                            DB::raw('SUM(rev) as total')
                        ]);

i did above but I'm only getting first two month of each year

Please sign in or create an account to participate in this conversation.