0
Beispiel der Ausgangsdaten:auf verschiedene Säulen
Project | Status | Emp1 | Emp2 | Emp3 |
--------------------------------------------------------------
Project 1 | Active | 10 | 10 | 20 |
Project 2 | Closed | 10 | 20 | 10 |
Project 1 | Closed | 20 | 10 | 20 |
Project 1 | Active | 20 | 20 | 10 |
Project 2 | Active | 20 | 10 | 20 |
Verwenden von SQL Server 2014 Ich habe 2 Abfragen, die ich brauche, um zu kombinieren 1 Tabelle von „Projekt“ gruppierte zu erhalten mit neuen Spalten von "Emp" basierend auf Status.
SELECT [Project],
SUM([Emp1]) as [Emp1_Act],
SUM([Emp2]) as [Emp2_Act],
SUM([Emp2]) as [Emp3_Act],
from t where status = 'Active'
SELECT [Project],
SUM([Emp1]) as [Emp1_Clo],
SUM([Emp2]) as [Emp2_Clo],
SUM([Emp2]) as [Emp3_Clo],
from t where status = 'Closed'
Angeforderte Daten:
Project | Emp1_Act | Emp2_Act | Emp3_Act | Emp1_Clo | Emp2_Clo | Emp3_Clo |
-----------------------------------------------------------------------------
Project 1 | 30 | 30 | 30 | 10 | 20 | 10 |
Project 2 | 20 | 10 | 20 | 20 | 10 | 20 |
Es funktioniert großartig, thx viel. – Dmitry