SELECT * FROM
(
SELECT * FROM
(
SELECT
loc.loc_name [abction],
stu_id,
stu.hs_grad [HigYear],
cst.consultiabcescription [Tyervice]
FROM student_tbl stu
LEFT JOIN location_tbl loc
ON stu.loc_id=loc.loc_id
LEFT JOIN consultittbl cst
ON stu.type_of_service=cst.consulting_service_ID
WHERE csting='Y'
AND hs_grad>=2012 AND hs_grad<=2022
) sd
pivot(
COUNT(stu_id) for [HigYear] in([2012],[2013],[2014],[2015],[2016],[2017],[2018],[2019],[2020],[2021],[2022])
) tbl
) newt ORDER BY [abction