get row count according to the month in the date in Laravel
问题 I want a query in laravel to group by data with dateofSale's month with the count of rows with the same month. here is my table and I want to output something like this numberOfSales | Month 2 Nov 1 Oct how can I do it? 回答1: You should be able to achieve this what you're after with: $data = \App\SaleData::selectRaw('COUNT(*) as count, YEAR(dateOfSale) year, MONTH(dateofSale) month') ->groupBy('year', 'month') ->get(); If you don't include the year as well then you'll have sales from different