Skip to content

Instantly share code, notes, and snippets.

@lwoodson
Created March 25, 2019 15:31
Show Gist options
  • Save lwoodson/0e827892f5346f2c94a428143ec28e9a to your computer and use it in GitHub Desktop.
Save lwoodson/0e827892f5346f2c94a428143ec28e9a to your computer and use it in GitHub Desktop.
sql = <<SQL
select
  count(*),
  date_trunc('day', o.created_at) as day
from
  orders o,
  stores s
where
  o.store_id = s.id
and
  s.store_type_id = 2
and
  o.created_at > current_date - interval '10' day
group by day
SQL

ActiveRecord::Base.connection.execute(sql).to_a

Shard1: 33745 Shard2: Shard3: 32114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment