I have a query where I want to calculate the percentage of sales of a certain product within its category. Thus I calculate the amount sales per product and use an analytic function and partition by category.
SELECT product_id, SUM(sales)/(SUM(sales) OVER(PARTITION BY category))
FROM table1
GROUP BY product_id
I get this error message:
AnalysisException: select list expression not produced by aggregation output (missing from GROUP BY clause?): sum(sales) / ((sum(sales) OVER (PARTITION BY category)))
Anyone that know how to solve this and why it happens?