Hello all -I am developing a query with a cube "rollup". I also need to provide the "percent of total" for each grouped item. See the Northwind example below where the red rows is what I'm after.EMPLOYEE | CATEGORY | SALES--------------------------------------Davolio | Meat/Poultry | 16346.0700Davolio | Seafood | 24947.0500Davolio | Total | 41293.1200Davolio | Meat/Poultry % | .3959Davolio | Seafood % | .6041Fuller | Meat/Poultry | 32973.5100Fuller | Seafood | 17561.7000Fuller | Total | 50535.2100Fuller | Meat/Poultry % | .6525Fuller | Seafood % | .3475Total | Meat/Poultry | 49319.58Total | Seafood | 42508.75Total | Total | 91828.3300Total | Meat/Poultry % |.5371Total | Seafood % | .4629
The query returns the total category sales for meat and seafood with a cube total on category and employee. I would like to have the percent of the cube total for each category with the group. For example, Meat/Poultry is 40% of the total category sales for employee Davolio.Unfortunately, I am unable to utilize Analysis Services on this particular project. I know I can accomplish this within the application code (asp) but I'm wondering if this is possible (or even recommended) using t-sql. Any input is appreciated. Thanks.Here's the sql for the query example: USE NorthwindSELECT CASE WHEN GROUPING(e.LastName)=1 THEN 'Total' ELSE e.LastName END AS Employee, CASE WHEN GROUPING (c.CategoryName)=1 THEN 'Total' ELSE c.CategoryName END AS Category, SUM(od.UnitPrice * od.Quantity) AS SalesFROM orders AS o INNER JOIN [order details] AS od ON (o.OrderID = od.OrderID) INNER JOIN employees AS e ON (o.EmployeeID = e.EmployeeID) INNER JOIN products AS p ON (od.ProductID = p.ProductID) INNER JOIN categories AS c ON (p.CategoryID = c.CategoryID)WHERE c.CategoryID IN (6,8) AND e.EmployeeID IN (1,2)GROUP BY e.LastName, c.CategoryNameWITH CUBEORDER BY GROUPING(e.LastName), e.LastName, GROUPING(c.CategoryName), c.CategoryName