Skip to content

Instantly share code, notes, and snippets.

@jondcampbell
Created October 9, 2015 23:08
Show Gist options
  • Save jondcampbell/88c572072f621d3f5ee3 to your computer and use it in GitHub Desktop.
Save jondcampbell/88c572072f621d3f5ee3 to your computer and use it in GitHub Desktop.
query a prices table, finding me the companies with the most products. uses laravel and db query builder. grouping and ordering
$companies = DB::table('prices')
->select(DB::raw('company_id, COUNT(*) as total_products'))
->groupBy('company_id')
->orderBy('total_products', 'desc')
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment