The code below doesn't work when I replace SUM(Sales) with ROUND(SUM(Sales),2)
, works otherwise. Sales field type = Double.
SELECT row_number() OVER (PARTITION BY Region) as Row_No, Name as Product, Category, Sales,
SUM(Sales) OVER (PARTITION BY Region, Category) as Category_Sales,
SUM(Sales) OVER (PARTITION BY Region) as Regional_Sales
FROM table
WHERE Region = "North"
ORDER BY Category, Sales;
Error thrown (MySQL 8) : OVER is not valid at this position, expecting ';' Tried using CONVERT() and CAST() to convert the aggregate values to INT. Didn't work either. That said, ROUND() works fine without OVER clause as in the code below.
SELECT Region, Category, ROUND(SUM(Sales),2) as Total_Sales
FROM table
GROUP BY Category;
What's going on and how do I make this work so that aggregate sales values are rounded to d decimals using ROUND(Val, d) alongwith the OVER clause?