I learn about CUBE and ROLLUP function today and I found it really usefull for generating reports. Let me give you one example where we can use ROLLUP and CUBE. Lets say you are developing the E-Commerce application and administrator wants the report which shows products purchased by all user group by product and buyer. You will say that’s really easy and can write the query as shown below, 1: SELECT CustomerName,CustomerName,SUM(Quantity*PricePerItem) 2: FROM Orders GROUP BY CustomerName,CustomerName Fig – (1) Group By clause. Which will returns the result as shown below, Fig – (2) Result of GROUP BY clause However what if you want result as display below, Fig – (3) Desire result Here ROLLUP and CUBE comes into the picture and help us. The above result is generated using ROLLUP. ROLLUP adds new row for each column used in GROUP BY clause. First have a look ...
Comments
Post a Comment