Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL with aggregates
Message
De
03/09/2013 11:30:32
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
SQL with aggregates
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01581896
Message ID:
01581896
Vues:
45
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform