Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Created July 10, 2014 07:33
Show Gist options
  • Select an option

  • Save benjamintanweihao/1eb77356dcd63938ac3f to your computer and use it in GitHub Desktop.

Select an option

Save benjamintanweihao/1eb77356dcd63938ac3f to your computer and use it in GitHub Desktop.
SELECT locations.name, SUM(items.count_on_hand) AS stock_count, SUM(items.count_on_hand * prices.amount) AS total_price
FROM spree_stock_locations AS locations
INNER JOIN spree_stock_items AS items
ON locations.id = items.stock_location_id
INNER JOIN spree_variants AS variants
ON variants.id = items.variant_id
INNER JOIN spree_prices AS prices
ON prices.variant_id = variants.id
WHERE prices.currency = 'SGD'
GROUP BY (locations.id)
ORDER BY name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment