SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL ROLLUP
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Cal88
Starting Member

3 Posts

Posted - 03/01/2014 :  17:21:54  Show Profile  Reply with Quote
I have a question regarding ROLLUP and how to use the operator.

I've been asked to retrieve a list showing the total repair cost per year displaying Transport Type, Manufacturer and Transport. The query I used is:

SELECT ty.Description AS TransportDescription,
t.SerialNumber AS Transport,
ty.Manufacturer,
SUM (r.RepairCost) AS RepairCost,
YEAR(r.EndWorkDate) AS [Year]
FROM Repair AS r
JOIN Transport AS t ON r.TransportNumber = t.TransportNumber
JOIN TransportType AS ty ON t.TransportTypeID = ty.TransportTypeID
GROUP BY ty.TransportTypeID,
ty.Description,
t.SerialNumber,
ty.Manufacturer,
YEAR(r.EndWorkDate)

How could I use the rollup function to display subtotals per Transport Type, Manufacturer and Transport?

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/02/2014 :  09:15:44  Show Profile  Reply with Quote

SELECT ty.Description AS TransportDescription,
t.SerialNumber AS Transport,
ty.Manufacturer,
SUM (r.RepairCost) AS RepairCost,
YEAR(r.EndWorkDate) AS [Year] 
FROM Repair AS r 
JOIN Transport AS t ON r.TransportNumber = t.TransportNumber
JOIN TransportType AS ty ON t.TransportTypeID = ty.TransportTypeID
GROUP BY ty.TransportTypeID,
ty.Description, 
t.SerialNumber,
ty.Manufacturer,
YEAR(r.EndWorkDate)
WITH ROLLUP


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000