sql 行转列

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。