You have duplicates because the
orderPeriod
field is in the
SELECT
statement.
Remove this field from both the
SELECT
and
GROUP BY
and you should get a total for each product without duplicates.
SELECT DISTINCT productName, SUM(quantity) AS Expr1
FROM WP_analytic WHERE (orderPeriod >= GETDATE() - 30) GROUP BY productName