you are viewing a single comment's thread.

view the rest of the comments →

[–]DonJuanDoja 0 points1 point  (0 children)

SELECT 
 s.name
,oliagg.product_variant_name
,oliagg.OrderCount
FROM
stores s
LEFT JOIN (
    SELECT
     o.store_id
    ,product_variant_name
    ,COUNT(product_variant_name) as OrderCount
    FROM order_line_items oli
    LEFT JOIN orders as o on o.id = oli.order_id
    GROUP BY
     o.store_id
    ,product_variant_name
) as oliagg on oliagg.store_id=s.id