Skip to content

Instantly share code, notes, and snippets.

@swrobel
Last active December 21, 2015 07:49

Revisions

  1. swrobel renamed this gist Sep 25, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. swrobel renamed this gist Sep 25, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. swrobel created this gist Aug 19, 2013.
    9 changes: 9 additions & 0 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    SELECT p.id,
    sum(quantity) AS num_sold
    FROM spree_orders o
    JOIN spree_line_items li ON o.ID = li.order_id
    JOIN spree_variants v ON li.variant_id = v.id
    JOIN spree_stock_items i ON v.id = i.variant_id
    JOIN spree_products p ON v.product_id = p.id
    WHERE o.state = 'complete'
    GROUP BY p.id