Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

several SUMs in one query each using different tables

Status
Not open for further replies.

sqlhelpme

Computer
Aug 3, 2005
1
I know how to get a sum in a query, but I need several different sums with different where clauses all in one query. Is that possible?

I.e. want, region, code, name, sum1 (from tableA where 1,2,3), sum2 (from tableB where 2,4,5)

I can only get 1 aggregate function to work per query.

select regionNumber, code, officename, sum(amt) as sum1
from projects p, ProjectActualCosts ac, actualCostTypes a, ProjectActual393 pa , cans c, vwoffices vw
where ac.actualCostTypeID= a.actualCostTypeID
and a.actualcostTypeIsPartOf <> 10 and pa.projectactualid = ac.projectactualid and
pa.projectid = p.projectid and
p.canid = c.canid and
vw.Officecode = p.doc and
[393date] between @BuildFY and @thisMonth group by regionnumber, code, officename

your help is appreciated. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor