Skip to content

Instantly share code, notes, and snippets.

@jpleau
Created November 20, 2013 05:00
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 jpleau/7557985 to your computer and use it in GitHub Desktop.
Save jpleau/7557985 to your computer and use it in GitHub Desktop.
class EmployeeSheet
belongs_to :sequence
end
class Sequence
has_many :employee_sheets
end
SELECT sequences.id, sequences.name, COUNT( employe_sheets.id ) AS nb
FROM employe_sheets
LEFT JOIN sequences ON sequences.id = employe_sheets.sequence_id
GROUP BY sequences.id
ORDER BY nb DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment