Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL with aggregates
Message
From
03/09/2013 11:30:32
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
SQL with aggregates
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01581896
Message ID:
01581896
Views:
46
Hello all -

I have another SELECT problem I have not encountered before. I have this query which seems to work OK.
SELECT a.system,
      a.subsystem, 
      COUNT(a.system) as numprojects, 
      SUM(total_cost) as Total_Cost
  FROM systems a
  inner join rtp_projects b on a.system = b.system and a.subsystem = b.subsystem  
  where b.Basecase = 1
  group by a.system, a.subsystem
  order by a.system, a.subsystem
Now I need to add another column that shows the sum of the Total_cost of the projects where Category = 'Capacity', something like this
SELECT a.system,
      a.subsystem, 
      COUNT(a.system) as numprojects, 
      SUM(total_cost) as Total_Cost,
      SUM(Total_cost where Category = 'Capacity')
  FROM systems a
  inner join rtp_projects b on a.system = b.system and a.subsystem = b.subsystem  
  where b.Basecase = 1
  group by a.system, a.subsystem
  order by a.system, a.subsystem
but I can't figure out the syntax for this additional column. Can someone help?
Thanks
Next
Reply
Map
View

Click here to load this message in the networking platform