Skip to content

Instantly share code, notes, and snippets.

@satoshin2071
Created March 26, 2013 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satoshin2071/5243543 to your computer and use it in GitHub Desktop.
Save satoshin2071/5243543 to your computer and use it in GitHub Desktop.
ActiveRecordでgroup Byしてカウントをして、カウント数でorderする via 酒と泪とRubyとRailsと
#===sample
#
#MP3プレイヤーのProductのmaker名をレコード数の多い順に並べてその結果のハッシュのkeyであるmaker名を配列として取得
#
Product.where(category: "MP3 Player").group(:maker).order('count_maker desc').count('maker').keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment