Feeds:
Posts
Comments

Posts Tagged ‘sql server rollup’

CREATE
TABLE Sales

(

[ProductCategoryName]
NVARCHAR(50),

[ProductName]
NVARCHAR(50),

[SalesAmount]
MONEY

)

GO

 

INSERT
Sales

SELECT
‘Bikes’,‘Mountain-100 Silver’,3399.99
UNION ALL

SELECT
‘Components’,‘Road-650 Black’,699.0982
UNION ALL

SELECT
‘Components’,‘Road-150 Red’,3578.27
UNION ALL

SELECT
‘Bikes’,‘Mountain-100 Silver’,3399.99
UNION ALL

SELECT
‘Bikes’,‘Mountain-100 Silver’,3399.99
UNION ALL

SELECT
‘Bikes’,‘Mountain-100 Black’,3374.99
UNION ALL

SELECT
‘Bikes’,‘Mountain-100 Silver’,3399.99
UNION ALL

SELECT
‘Components’,‘Road-150 Red’,3578.27
UNION ALL

SELECT
‘Components’,‘Road-150 Red’,3578.27
UNION ALL

SELECT
‘Components’,‘Road-150 Red’,3578.27
UNION ALL

SELECT
‘Components’,‘Road-150 Red’,3578.27
UNION ALL

SELECT
‘Components’,‘Road-650 Red’,699.0982

GO

 

SELECT
* FROM
Sales

GO

 

 

GROUP BY

SELECT
ProductCategoryName,ProductName,SUM(SalesAmount)AS TotalSalesAmount FROM
Sales

GROUP
BY ProductCategoryName,ProductName

 

 

WITH ROLLUP 

SELECT
ProductCategoryName,ProductName,SUM(SalesAmount)AS TotalSalesAmount FROM
Sales

GROUP
BY ProductCategoryName,ProductName

WITH
ROLLUP

 

 

Read Full Post »

%d bloggers like this: