SELECT vpw.Location, p.PIN, p.ProductCode, p.PricingType, COUNT(od.productcode) AS 'Count of Sales', p.Cost, p.HasPhoto
FROM products.pins p
JOIN products._VPW vpw ON p.PIN = vpw.MFG_SKU
LEFT JOIN custopayted.orderdetails od ON p.ProductCode = od.ProductCode
WHERE p.HasPhoto = 0
AND vpw.TX > 0
AND p.Parent = ''
GROUP BY vpw.Location, p.PIN, p.ProductCode
ORDER BY p.PricingType, COUNT(od.productcode) DESC



-- SELECT vpw.Location, p.PIN, p.ProductCode, p.Popularity, p.Cost, p.HasPhoto
-- FROM products.pins p
-- JOIN products._VPW vpw ON p.PIN = vpw.MFG_SKU
-- WHERE (p.HasPhoto != 1 or p.HasPhoto = 0)
-- AND vpw.TX > 0
-- ORDER BY vpw.Location, vpw.MFG_SKU