Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total a column 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am trying to get a column total for WD1, preferably at the bottom if I can, I have tried the wizard but with no avail.

SELECT Projects.ProjectName, Forecast.WD1
FROM Projects INNER JOIN (Handlers INNER JOIN Forecast ON Handlers.HandlerID = Forecast.HandlerID) ON Projects.ProjID = Handlers.ProjID
GROUP BY Projects.ProjectName, Forecast.WD1;

Many thanks
 
Try
Code:
SELECT Projects.ProjectName, [COLOR=red]SUM([/color]Forecast.WD1[COLOR=red]) As SumWD1[/color]

FROM Projects INNER JOIN (Handlers 
     INNER JOIN Forecast ON Handlers.HandlerID = Forecast.HandlerID) 
     ON Projects.ProjID = Handlers.ProjID

GROUP BY Projects.ProjectName;
 
Many thanks Golam. However it did not give me a total of WD1 for all records, just gave a column of individual row totals. My aim is to try and get a foot/column total. Thanks the same.
 
Since your submitted query showed ProjectName, I assumed that you wanted totals by ProjectName. If you just want one grand total then
Code:
SELECT SUM(Forecast.WD1) As SumWD1

FROM Projects INNER JOIN (Handlers 
     INNER JOIN Forecast ON Handlers.HandlerID = Forecast.HandlerID) 
     ON Projects.ProjID = Handlers.ProjID
 
Sorry Golam, maybe I have confused the issue?? I am trying to get this:

Project Name | WD1 |
Proj 1 | 5 |
Proj 2 | 6 |
Total | 11 |

Does that help. Thanks again
 
OK. Combine the two
Code:
SELECT Projects.ProjectName, SUM(Forecast.WD1) As SumWD1

FROM Projects INNER JOIN (Handlers 
     INNER JOIN Forecast ON Handlers.HandlerID = Forecast.HandlerID) 
     ON Projects.ProjID = Handlers.ProjID

GROUP BY Projects.ProjectName

UNION ALL

SELECT "Total", SUM(Forecast.WD1) As SumWD1

FROM Projects INNER JOIN (Handlers 
     INNER JOIN Forecast ON Handlers.HandlerID = Forecast.HandlerID) 
     ON Projects.ProjID = Handlers.ProjID
 
Excellent Golam, thanks a lot. Just what I wanted. Have a star and thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top