Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Last active July 3, 2017 15:58
Show Gist options
  • Save GreatPotato/4494595 to your computer and use it in GitHub Desktop.
Save GreatPotato/4494595 to your computer and use it in GitHub Desktop.
Gets the 50 top selling products that cost over 15.00
SELECT t3.name, t3.sku, t3.price, count(t1.shop_product_id) AS "Number of orders"
FROM shop_order_items t1
LEFT JOIN shop_orders t2
ON t1.shop_order_id = t2.id
LEFT JOIN shop_products t3
ON t1.shop_product_id = t3.id
WHERE t2.payment_processed != ''
AND t3.price > 15.00
GROUP BY t1.shop_product_id
ORDER BY count(t1.shop_product_id) DESC
LIMIT 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment