Puis-je combiner un PIVOT avec une jointure Interne dans microsoft SQL server?

J'ai de la requête SQL suivante:

SELECT CountryID, [10201] AS CountryGDPPerCapita, [10677] AS LifeExpTotal
FROM
(
    SELECT CountryID,FieldID,numeric 
    FROM globaledge.dbo.DIBS_Data
    WHERE CountryID IN (3,5)
    AND FieldID IN (10201,10677)
    AND year = 2002
)  SourceTable
PIVOT
(
    MAX(numeric)
    FOR FieldID IN ([10201],[10677])
) AS PivotTable
ORDER BY PivotTable.CountryID

Cela renvoie à quelque chose qui ressemble à ceci:

CountryID CountryGDPPerCapita LifeExpTotal

3 35985.78 77.24

5 9147.7 74.54

Puis j'ai une autre requête comme suit:

SELECT CountryName, CountryGDP, CountryGDPGrowth 
FROM globaledge.dbo.Country_Statistics 
WHERE CountryID IN (3,5) 
AND year=2002
Order By CountryName

Qui produit le texte suivant:

CountryName CountryGDP CountryGDPGrowth

Mexique 1567000000000000 1.3

États-Unis 14440000000000000 0.4

Noter également, j'ai CountryID dans les deux tables, qui se réfèrent à la même pays. Ce que je veux, c'est créer une Requête SQL, peut-être avec une JOINTURE INTERNE, qui serait de retour suivantes:

CountryName CountryGDP CountryGDPGrowth CountryGDPPerCapita LifeExpTotal

Mexique 156700000000000000 1.3 35985.78 77.24

États-Unis 144400000000000000 0.4 9147.7 74.54

Quelqu'un pourrait-il m'aider à faire cette requête? ou me dire si c'est possible?

OriginalL'auteur adhanlon | 2010-02-19