Заголовок - я полагаю, что-то не так с UNPIVOT? Я просто не могу понять, что. Любая помощь будет оценена - спасибо.
WITH IPEDSData AS
(
SELECT
[UnitID]
,[Institution Name]
,[Peer]
,[State abbreviation]
,[Sector of institution]
,CASE
WHEN FIELD LIKE '%2018' THEN '2018'
WHEN FIELD LIKE '%2017' THEN '2017'
WHEN FIELD LIKE '%2016' THEN '2016'
WHEN FIELD LIKE '%2015' THEN '2015'
WHEN FIELD LIKE '%2014' THEN '2014'
END ReportYear
,CASE
WHEN FIELD LIKE 'Financial aid cohort%' THEN 'Financial Aid Cohort'
WHEN FIELD LIKE 'Number of students awarded grant aid%' THEN 'Number of Students Awarded Grant Aid'
WHEN FIELD LIKE 'Percent of students awarded grant aid%' THEN 'Percent of Students Awarded Grant Aid'
WHEN FIELD LIKE 'Total amount of grant aid%' THEN 'Total Amount of Grant Aid'
WHEN FIELD LIKE 'Average amount of grant aid%' THEN 'Average Amount of Grant Aid'
WHEN FIELD LIKE 'Number of students awarded Pell grants%' THEN 'Number of Students Awarded Pell Grants'
WHEN FIELD LIKE 'Percent of students awarded Pell grants%' THEN 'Percent of Students Awarded Pell Grants'
WHEN FIELD LIKE 'Total amount of Pell grant aid awarded%' THEN 'Total Amount of Pell Grant Aid Awarded'
WHEN FIELD LIKE 'Average amount of Pell grant aid awarded%%' THEN 'Average Amount of Pell Grant Aid Awarded'
WHEN FIELD LIKE 'Number of students awarded federal student loans%' THEN 'Number of Students Awarded Federal Student Loans'
WHEN FIELD LIKE 'Percent of students awarded federal student loans%' THEN 'Percent of Students Awarded Federal Student Loans'
WHEN FIELD LIKE 'Total amount of federal student loans%' THEN 'Total Amount of Federal Student Loans'
WHEN FIELD LIKE 'Average amount of federal student loans%' THEN 'Average Amount of Federal Student Loans'
END FinancialAidCategory
,Result
FROM (
SELECT
[UnitID]
,[Institution Name]
,[Peer]
,[State abbreviation]
,[Sector of institution]
,[FIELD]
,[Result]
FROM [data_IPEDS_FinancialAidExtractWithPeers]
UNPIVOT (
[Result] FOR
[FIELD] IN (
[Financial aid cohort 2018]
,[Number of students awarded grant aid 2018]
,[Percent of students awarded grant aid 2018]
,[Total amount of grant aid 2018]
,[Average amount of grant aid 2018]
,[Number of students awarded Pell grants 2018]
,[Percent of students awarded Pell grants 2018]
,[Total amount of Pell grant aid awarded 2018]
,[Average amount Pell grant aid awarded 2018]
,[Number of students awarded federal student loans 2018]
,[Percent of students awarded federal student loans 2018]
,[Total amount of federal student loans awarded 2018]
,[Average amount of federal student loans awarded 2018]
,[Financial aid cohort 2017]
,[Number of students awarded grant aid 2017]
,[Percent of students awarded grant aid 2017]
,[Total amount of grant aid 2017]
,[Average amount of grant aid 2017]
,[Number of students awarded Pell grants 2017]
,[Percent of students awarded Pell grants 2017]
,[Total amount of Pell grant aid awarded 2017]
,[Average amount Pell grant aid awarded 2017]
,[Number of students awarded federal student loans 2017]
,[Percent of students awarded federal student loans 2017]
,[Total amount of federal student loans awarded 2017]
,[Average amount of federal student loans awarded 2017]
,[Financial aid cohort 2016]
,[Number of students awarded grant aid 2016]
,[Percent of students awarded grant aid 2016]
,[Total amount of grant aid 2016]
,[Average amount of grant aid 2016]
,[Number of students awarded Pell grants 2016]
,[Percent of students awarded Pell grants 2016]
,[Total amount of Pell grant aid awarded 2016]
,[Average amount Pell grant aid awarded 2016]
,[Number of students awarded federal student loans 2016]
,[Percent of students awarded federal student loans 2016]
,[Total amount of federal student loans awarded 2016]
,[Average amount of federal student loans awarded 2016]
,[Financial aid cohort 2015]
,[Number of students awarded grant aid 2015]
,[Percent of students awarded grant aid 2015]
,[Total amount of grant aid 2015]
,[Average amount of grant aid 2015]
,[Number of students awarded Pell grants 2015]
,[Percent of students awarded Pell grants 2015]
,[Total amount of Pell grant aid awarded 2015]
,[Average amount Pell grant aid awarded 2015]
,[Number of students awarded federal student loans 2015]
,[Percent of students awarded federal student loans 2015]
,[Total amount of federal student loans awarded 2015]
,[Average amount of federal student loans awarded 2015]
,[Financial aid cohort 2014]
,[Number of students awarded grant aid 2014]
,[Percent of students awarded grant aid 2014]
,[Total amount of grant aid 2014]
,[Average amount of grant aid 2014]
,[Number of students awarded Pell grants 2014]
,[Percent of students awarded Pell grants 2014]
,[Total amount of Pell grant aid awarded 2014]
,[Average amount Pell grant aid awarded 2014]
,[Number of students awarded federal student loans 2014]
,[Percent of students awarded federal student loans 2014]
,[Total amount of federal student loans awarded 2014]
,[Average amount of federal student loans awarded 2014]
)
) AS U
) AS X
)