计数和总和并显示空单元格的枢轴结果

发布于 2025-02-11 01:52:22 字数 7934 浏览 0 评论 0原文

I have the following SQL:

    SELECT t6.StudentId,
       t6.FirstName,
       t2.Code,
       t2.Title,
       t2.Credit,
       t2.SemesterId
FROM
(
    SELECT t1.*,
           t7.Code,
           t7.Title,
           t7.Credit
    FROM StudentCourses t1
        JOIN CourseOfferings t7
            on t7.Id = t1.CourseOfferingId
    WHERE t1.SemesterId = 63
          AND t1.Status IN ( 'Approved', 'Registered')
) AS t2
    JOIN Students t6
        on t6.StudentId = t2.StudentId
    JOIN StudentCurriculum t3
        on t3.StudentId = t2.StudentId
    JOIN Curriculums t4
        on t4.Id = t3.CurriculumId
    JOIN StudyPrograms t5
        on t5.Id = t4.StudyProgramId
WHERE t5.FacultyId = 2

that gives me the following result:

StudentIdFirstNameCodeTitleCreditSemesterId
7505ToranongMKTG3204Marketing Channels Management and Distribution3.063
7505ToranongGENL1111Health and Wellness3.063
7505ToranongMNGT2206Managing Human Capital3.063
7505ToranongMKTG3206Global Marketing3.063
7505ToranongMKTG3205Integrated Marketing Communication3.063
7505ToranongGENL1100Seminar in Character Dev0.063
7505ToranongBUAD3305English for Career3.063
7507KannikaGENL1100Seminar in Character Dev0.063
7507KannikaACCT3213Public Sector Accounting3.063
7507KannikaACCT3206Advanced Accounting II3.063
7507KannikaACCT3209Internal Audit and Risk Managemen3.063
7507KannikaACCT3211Cost Management3.063
7507KannikaBUAD3305English for Career3.063
7510SiripornACCT3211Cost Management3.063
7510SiripornBUAD3305English for Career3.063
7510SiripornACCT3206Advanced Accounting II3.063
7510SiripornACCT3213Public Sector Accounting3.063
7510SiripornGENL1100Seminar in Character Dev0.063
7510SiripornACCT3209Internal Audit and Risk Managemen3.063
7512AphisitMKTG3206Global Marketing3.063
7512AphisitMKTG3205Integrated Marketing Communication3.063
7512AphisitMNGT2206Managing Human Capital3.063
7512AphisitGENL1111Health and Wellness3.063
7512AphisitGENL1100Seminar in Character Dev0.063
7512AphisitBUAD3305English for Career3.063
7512AphisitMKTG3204Marketing Channels Management and Distribution3.063
7517PitchayaGENL1100Seminar in Character Dev0.063
7517PitchayaACCT3206Advanced Accounting II3.063
7517PitchayaACCT3209内部审计和风险管理员3.063

[省略了简短

]想要将结果转移到以下格式中:

单击此处查看表

ID名称通信BUAD355国际业务BUAD456全球业务ENGL237亚洲文学Engl243人际交流ENGL251公共演讲ENGL254应用语音和词语ENGL258重要阅读和思考ENGL259专业写作Enkl341社交媒体媒体通信Engl341社交媒体通信ENGL352英语Grammar Grammar GrammarEngl392介绍Resory&Amp&Amp&Amp&Amp&Amp&Amp&Amp;著作Hist212 Hist的介绍。 文明人类计算机互动网络和数据通信数学MKTG232原则钢琴语音PSYC115入门入门
MATH081Musc121中级西方IT272课程代数MUSC111市场营销IT28223333113
7148Chanraiya33393
7149Anattanon3333124
7150Rotcharat33323145
7151Sosipho33333155
7152Porapat33333155
7153Zhou33333 33 3186
7154SU33333 33186
7155Liu33 333 3311177

第一行是课程学分,您可以在上图中看到它。 我正在SQL Server 2016 Express上编写SQL。

I have the following SQL:

    SELECT t6.StudentId,
       t6.FirstName,
       t2.Code,
       t2.Title,
       t2.Credit,
       t2.SemesterId
FROM
(
    SELECT t1.*,
           t7.Code,
           t7.Title,
           t7.Credit
    FROM StudentCourses t1
        JOIN CourseOfferings t7
            on t7.Id = t1.CourseOfferingId
    WHERE t1.SemesterId = 63
          AND t1.Status IN ( 'Approved', 'Registered')
) AS t2
    JOIN Students t6
        on t6.StudentId = t2.StudentId
    JOIN StudentCurriculum t3
        on t3.StudentId = t2.StudentId
    JOIN Curriculums t4
        on t4.Id = t3.CurriculumId
    JOIN StudyPrograms t5
        on t5.Id = t4.StudyProgramId
WHERE t5.FacultyId = 2

that gives me the following result:

StudentIdFirstNameCodeTitleCreditSemesterId
7505ToranongMKTG3204Marketing Channels Management and Distribution3.063
7505ToranongGENL1111Health and Wellness3.063
7505ToranongMNGT2206Managing Human Capital3.063
7505ToranongMKTG3206Global Marketing3.063
7505ToranongMKTG3205Integrated Marketing Communication3.063
7505ToranongGENL1100Seminar in Character Dev0.063
7505ToranongBUAD3305English for Career3.063
7507KannikaGENL1100Seminar in Character Dev0.063
7507KannikaACCT3213Public Sector Accounting3.063
7507KannikaACCT3206Advanced Accounting II3.063
7507KannikaACCT3209Internal Audit and Risk Managemen3.063
7507KannikaACCT3211Cost Management3.063
7507KannikaBUAD3305English for Career3.063
7510SiripornACCT3211Cost Management3.063
7510SiripornBUAD3305English for Career3.063
7510SiripornACCT3206Advanced Accounting II3.063
7510SiripornACCT3213Public Sector Accounting3.063
7510SiripornGENL1100Seminar in Character Dev0.063
7510SiripornACCT3209Internal Audit and Risk Managemen3.063
7512AphisitMKTG3206Global Marketing3.063
7512AphisitMKTG3205Integrated Marketing Communication3.063
7512AphisitMNGT2206Managing Human Capital3.063
7512AphisitGENL1111Health and Wellness3.063
7512AphisitGENL1100Seminar in Character Dev0.063
7512AphisitBUAD3305English for Career3.063
7512AphisitMKTG3204Marketing Channels Management and Distribution3.063
7517PitchayaGENL1100Seminar in Character Dev0.063
7517PitchayaACCT3206Advanced Accounting II3.063
7517PitchayaACCT3209Internal Audit and Risk Managemen3.063

[omitted for brevity]SQL result

I want to pivot the result into the following format:

Click here to view the table

IDNameBUAD134 Business CommunicationBUAD355 International BusinessBUAD456 Global BusinessENGL237 Asian LiteratureENGL243 Interpersonal CommunicationENGL251 Public SpeakingENGL254 Applied Phonetics and DictionENGL258 Critical Reading and ThinkingENGL259 Professional WritingENGL341 Social Media CommunicationsENGL352 English GrammarENGL392 Introductory Res Methods & WritingsHIST212 Intro to Hist. of Western CivilizationIT272 Human-Computer InteractionIT282 Networking and Data CommunicationsMATH081 Intermediate AlgebraMKTG232 Principles of MarketingMUSC111 Introductory Piano LessonsMUSC121 Introductory Voice LessonsPSYC115 General PsychologyTotal Credits RegisteredNumber of Courses Registered
33333333333323333113
7148Chanraiya33393
7149Anattanon3333124
7150Rotcharat33323145
7151Sosipho33333155
7152Porapat33333155
7153Zhou333333186
7154Su333333186
7155Liu3333311177

The first row is the course credit as you can see it in the image above.
I'm writing the SQL on SQL SERVER 2016 Express.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文