IN SQL (and if possible how to write it in Laravel Eloquent), if there are 10 MySQL rows having value IN', 4 rows having value 'US', 7 rows having value 'FR'; I want the query result to be three rows:
- IN | 10
- US | 4
- FR | 7
CodePudding user response:
SELECT column_name, count (*) as c FROM table_name GROUP BY column_name ORDER BY c DESC
CodePudding user response:
Model::query()->groupBy('country_name')->select('counrty_name',DB::raw('COUNT(1)'))