I am trying to produce a pivoted table.
I have aliased column names, since the columns are being aggregated.
Why isn't my alias usable?
Since you are aggregating the data in the
Enrollment column via
sum(Enrollment) that column is no longer available for the final select list. Remove it from the final select list and the query should work without any issues.
The thing to remember when using a
PIVOT is columns you use inside of the statement are being replaced because you are converting the values into new columns. In the case of your query, both the
ProgramType are not available in the final select.