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 Enrollment
and ProgramType
are not available in the final select.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.