Skip to content

Instantly share code, notes, and snippets.

@Raven24
Created August 28, 2015 14:55
Show Gist options
  • Save Raven24/3f61b2cc6e91091728a1 to your computer and use it in GitHub Desktop.
Save Raven24/3f61b2cc6e91091728a1 to your computer and use it in GitHub Desktop.
find duplicates + how many
count = Pod.arel_table[:host].count.as("dup_count")
col = Arel::Nodes::SqlLiteral.new("dup_count")
Pod.
group(Pod.arel_table[:host]).
having(col.gt(1)).order(col.desc).
pluck(count.to_sql, :host).
each do |pod|
pp pod
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment