Skip to content

Instantly share code, notes, and snippets.

@ikzekly
Last active September 2, 2018 20:24
Show Gist options
  • Save ikzekly/ad363b8dcdb7a067840ef5923caa0249 to your computer and use it in GitHub Desktop.
Save ikzekly/ad363b8dcdb7a067840ef5923caa0249 to your computer and use it in GitHub Desktop.
Take all users, who having five and less invoices
User.joins('LEFT JOIN "invoices" ON "invoices"."merchant_id" = "users"."id"').group("users.id").having("count(*) <= ?", 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment