我想的cols轉換爲行,以適應格式的圖像 行這是我的查詢:轉換列使用數據透視
Select dt1.Year,dt1.oneyearret as '1-Year Retention',dt2.twoyearret as '2-Year Retention',dt4.fouryeargrad as '4-Year Graduation Rate',dt5.fiveyeargrad as '5-Year Graduation Rate',dt6.sixyeargrad as '6-Year Graduation Rate' from
(select case WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2015' then '2015' WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2016' then '2016' else (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) end as 'Year',
cast(convert(varchar,(Convert(Money,SUM(rg.RET1_FF),1)/Convert(Money,SUM(rg.COHORT_COUNT),1))*100,1) as numeric(10,1)) as oneyearret
from vw_Retention_Graduation_F rg
inner join dim_Time t
on rg.TIME_KEY = t.TIME_KEY
inner join dim_Part_Full pf
on rg.PART_FULL_KEY=pf.PART_FULL_KEY
inner join dim_Student_Level sl
on rg.STUDENT_LEVEL_KEY=SL.STUDENT_LEVEL_KEY
inner join dim_Student_Population sp
on rg.STUDENT_POPULATION_KEY=sp.STUDENT_POPULATION_KEY
inner join dim_College c
on rg.COLLEGE_KEY = c.COLLEGE_KEY
WHERE t.ACADEMIC_PERIOD between 201527 and 201627
AND pf.PART_FULL = 'F'
AND sl.STUDENT_LEVEL = 'UG'
AND sp.STUDENT_POPULATION = 'N'
GROUP BY (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4)))) dt1 inner join
(select case WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2014' then '2015' WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2015' then '2016' else (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) end as 'Year',
cast(convert(varchar,(Convert(Money,SUM(rg.RET2_FF),1)/Convert(Money,SUM(rg.COHORT_COUNT),1))*100,1) as numeric(10,1)) as twoyearret
from vw_Retention_Graduation_F rg
inner join dim_Time t
on rg.TIME_KEY = t.TIME_KEY
inner join dim_Part_Full pf
on rg.PART_FULL_KEY=pf.PART_FULL_KEY
inner join dim_Student_Level sl
on rg.STUDENT_LEVEL_KEY=SL.STUDENT_LEVEL_KEY
inner join dim_Student_Population sp
on rg.STUDENT_POPULATION_KEY=sp.STUDENT_POPULATION_KEY
inner join dim_College c
on rg.COLLEGE_KEY = c.COLLEGE_KEY
WHERE t.ACADEMIC_PERIOD between 201427 and 201527
AND pf.PART_FULL = 'F'
AND sl.STUDENT_LEVEL = 'UG'
AND sp.STUDENT_POPULATION = 'N'
GROUP BY (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4)))) dt2 on dt1.Year = dt2.year
inner join
(select case WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2012' then '2015' WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2013' then '2016' else (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) end as 'Year',
cast(convert(varchar,(Convert(Money,SUM(rg.GRAD4_FF),1)/Convert(Money,SUM(rg.COHORT_COUNT),1))*100,1) as numeric(10,1)) as fouryeargrad
from vw_Retention_Graduation_F rg
inner join dim_Time t
on rg.TIME_KEY = t.TIME_KEY
inner join dim_Part_Full pf
on rg.PART_FULL_KEY=pf.PART_FULL_KEY
inner join dim_Student_Level sl
on rg.STUDENT_LEVEL_KEY=SL.STUDENT_LEVEL_KEY
inner join dim_Student_Population sp
on rg.STUDENT_POPULATION_KEY=sp.STUDENT_POPULATION_KEY
inner join dim_College c
on rg.COLLEGE_KEY = c.COLLEGE_KEY
WHERE t.ACADEMIC_PERIOD between 201227 and 201327
AND pf.PART_FULL = 'F'
AND sl.STUDENT_LEVEL = 'UG'
AND sp.STUDENT_POPULATION = 'N'
GROUP BY (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4)))) dt4 on dt2.Year = dt4.year
inner join
(select case WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2011' then '2015' WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2012' then '2016' else (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) end as 'Year',
cast(convert(varchar,(Convert(Money,SUM(rg.GRAD5_FF),1)/Convert(Money,SUM(rg.COHORT_COUNT),1))*100,1) as numeric(10,1)) as fiveyeargrad
from vw_Retention_Graduation_F rg
inner join dim_Time t
on rg.TIME_KEY = t.TIME_KEY
inner join dim_Part_Full pf
on rg.PART_FULL_KEY=pf.PART_FULL_KEY
inner join dim_Student_Level sl
on rg.STUDENT_LEVEL_KEY=SL.STUDENT_LEVEL_KEY
inner join dim_Student_Population sp
on rg.STUDENT_POPULATION_KEY=sp.STUDENT_POPULATION_KEY
inner join dim_College c
on rg.COLLEGE_KEY = c.COLLEGE_KEY
WHERE t.ACADEMIC_PERIOD between 201127 and 201227
AND pf.PART_FULL = 'F'
AND sl.STUDENT_LEVEL = 'UG'
AND sp.STUDENT_POPULATION = 'N'
GROUP BY (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4)))) dt5 on dt4.Year = dt5.year
inner join
(select case WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2010' then '2015' WHEN (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) ='2011' then '2016' else (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4))) end as 'Year',
cast(convert(varchar,(Convert(Money,SUM(rg.GRAD6_FF),1)/Convert(Money,SUM(rg.COHORT_COUNT),1))*100,1) as numeric(10,1)) as sixyeargrad
from vw_Retention_Graduation_F rg
inner join dim_Time t
on rg.TIME_KEY = t.TIME_KEY
inner join dim_Part_Full pf
on rg.PART_FULL_KEY=pf.PART_FULL_KEY
inner join dim_Student_Level sl
on rg.STUDENT_LEVEL_KEY=SL.STUDENT_LEVEL_KEY
inner join dim_Student_Population sp
on rg.STUDENT_POPULATION_KEY=sp.STUDENT_POPULATION_KEY
inner join dim_College c
on rg.COLLEGE_KEY = c.COLLEGE_KEY
WHERE t.ACADEMIC_PERIOD between 201027 and 201127
AND pf.PART_FULL = 'F'
AND sl.STUDENT_LEVEL = 'UG'
AND sp.STUDENT_POPULATION = 'N'
GROUP BY (CONVERT(INT,SUBSTRING(ACADEMIC_PERIOD_all,1,4)))) dt6 on dt5.Year = dt6.year
哇查詢是嚴重難看。一些格式化將把文本牆變成不會讓其他人想要自殺的東西。 –
如果你可以讀它很好,否則不打擾。 –
所以我幫你格式化你的文章,你告訴我不要打擾。對於那些試圖幫助你的人來說,這不是一種很好的態度。 –