Skip to content

Instantly share code, notes, and snippets.

@thegorgon
Last active August 29, 2015 14:14
Show Gist options
  • Save thegorgon/86c662d15bfbd893f16d to your computer and use it in GitHub Desktop.
Save thegorgon/86c662d15bfbd893f16d to your computer and use it in GitHub Desktop.
Query for Superbowl Offer Volume by Region
SELECT
service_regions.name region_name,
SUM(cart_items.quantity) total_quantity,
offers.name offer_name
FROM
orders
INNER JOIN cart_items ON cart_items.order_id = orders.id
INNER JOIN offers ON offers.id = cart_items.offer_id
INNER JOIN service_regions ON service_regions.id = orders.service_region_id
WHERE
DATE(orders.delivery_window_starts_at - INTERVAL '7' HOUR) = '2015-02-01'
GROUP BY
service_regions.name,
offers.name
ORDER BY region_name ASC, total_quantity DESC;
@jeffreyiacono
Copy link

this must be run against the production follower db

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