<tfoot id='EDJJu'></tfoot>

      <small id='EDJJu'></small><noframes id='EDJJu'>

        <legend id='EDJJu'><style id='EDJJu'><dir id='EDJJu'><q id='EDJJu'></q></dir></style></legend>
        <i id='EDJJu'><tr id='EDJJu'><dt id='EDJJu'><q id='EDJJu'><span id='EDJJu'><b id='EDJJu'><form id='EDJJu'><ins id='EDJJu'></ins><ul id='EDJJu'></ul><sub id='EDJJu'></sub></form><legend id='EDJJu'></legend><bdo id='EDJJu'><pre id='EDJJu'><center id='EDJJu'></center></pre></bdo></b><th id='EDJJu'></th></span></q></dt></tr></i><div id='EDJJu'><tfoot id='EDJJu'></tfoot><dl id='EDJJu'><fieldset id='EDJJu'></fieldset></dl></div>

        • <bdo id='EDJJu'></bdo><ul id='EDJJu'></ul>

        SQL Server 2005 在未知列数上透视

        时间:2023-07-16
            <tbody id='AGwv4'></tbody>
            <bdo id='AGwv4'></bdo><ul id='AGwv4'></ul>
              • <small id='AGwv4'></small><noframes id='AGwv4'>

                <tfoot id='AGwv4'></tfoot>
              • <i id='AGwv4'><tr id='AGwv4'><dt id='AGwv4'><q id='AGwv4'><span id='AGwv4'><b id='AGwv4'><form id='AGwv4'><ins id='AGwv4'></ins><ul id='AGwv4'></ul><sub id='AGwv4'></sub></form><legend id='AGwv4'></legend><bdo id='AGwv4'><pre id='AGwv4'><center id='AGwv4'></center></pre></bdo></b><th id='AGwv4'></th></span></q></dt></tr></i><div id='AGwv4'><tfoot id='AGwv4'></tfoot><dl id='AGwv4'><fieldset id='AGwv4'></fieldset></dl></div>
                <legend id='AGwv4'><style id='AGwv4'><dir id='AGwv4'><q id='AGwv4'></q></dir></style></legend>

                  本文介绍了SQL Server 2005 在未知列数上透视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在处理一组类似于以下内容的数据.

                  <块引用>

                  学生姓名 |作业名称 |年级-------------------------------学生A |作业 1 |100学生A |作业 2 |80学生A |总计 |180学生乙 |作业 1 |100学生乙 |作业 2 |80学生乙 |作业 3 |100学生乙 |总计 |280

                  分配的名称和数量是动态的,我需要得到类似于以下的结果.

                  <块引用>

                  学生 |作业 1 |作业 2 |作业 3 |全部的--------------------------------------------------------------------学生A |100 |80 |空|180学生乙 |100 |80 |100 |280

                  现在理想情况下,我想根据可以包含/与每个作业关联的截止日期"对列进行排序.如果可能的话,总数应该放在最后(如果可能,它可以被计算并从查询中删除.)

                  我知道如何通过简单地命名列使用数据透视表来完成 3 个分配,它正在尝试以一种动态的方式来完成,但我还没有找到一个好的解决方案.我正在尝试在 SQL Server 2005 上执行此操作

                  编辑

                  理想情况下,我想在不使用动态 SQL 的情况下实现这一点,因为这违反了政策.如果这是不可能的……那么动态 SQL 的工作示例将起作用.

                  解决方案

                  我知道你说没有动态 SQL,但我看不出有什么方法可以直接用 SQL.

                  如果您在 数据透视表和连接列和sql 2005中的PIVOT

                  动态SQL 不容易被注入,也没有充分的理由禁止它.另一种可能性(如果数据很少更改)是进行代码生成 - 而不是动态 SQLSQL 定期生成到存储过程.

                  I am working with a set of data that looks something like the following.

                  StudentName  | AssignmentName |  Grade
                  ---------------------------------------
                  StudentA     | Assignment 1   | 100
                  StudentA     | Assignment 2   | 80
                  StudentA     | Total          | 180
                  StudentB     | Assignment 1   | 100
                  StudentB     | Assignment 2   | 80
                  StudentB     | Assignment 3   | 100
                  StudentB     | Total          | 280
                  

                  The name and number of assignments are dynamic, I need to get results simlilar to the following.

                  Student      | Assignment 1  | Assignment 2  | Assignment 3  | Total
                  --------------------------------------------------------------------
                  Student A    | 100           | 80            | null          | 180
                  Student B    | 100           | 80            | 100           | 280
                  

                  Now ideally I would like to sort the column based on a "due date" that could be included/associated with each assignment. The total should be at the end if possible (It can be calculated and removed from the query if possible.)

                  I know how to do it for the 3 assignments using pivot with simply naming the columns, it is trying to do it in a dynamic fashion that I haven't found a GOOD solution for yet. I am trying to do this on SQL Server 2005

                  EDIT

                  Ideally I would like to implement this WITHOUT using Dynamic SQL, as that is against the policy. If it isn't possible...then a working example with Dynamic SQL will work.

                  解决方案

                  I know you said no dynamic SQL, but I don't see any way to do it in straight SQL.

                  If you check out my answers to similar problems at Pivot Table and Concatenate Columns and PIVOT in sql 2005

                  The dynamic SQL there is not vulnerable to injection, and there is no good reason to prohibit it. Another possibility (if the data is changing very infrequently) is to do code-generation - instead of dynamic SQL, the SQL is generated to a stored procedure on a regular basis.

                  这篇关于SQL Server 2005 在未知列数上透视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <legend id='WzWMX'><style id='WzWMX'><dir id='WzWMX'><q id='WzWMX'></q></dir></style></legend>
                    <tbody id='WzWMX'></tbody>
                  • <tfoot id='WzWMX'></tfoot>

                    <i id='WzWMX'><tr id='WzWMX'><dt id='WzWMX'><q id='WzWMX'><span id='WzWMX'><b id='WzWMX'><form id='WzWMX'><ins id='WzWMX'></ins><ul id='WzWMX'></ul><sub id='WzWMX'></sub></form><legend id='WzWMX'></legend><bdo id='WzWMX'><pre id='WzWMX'><center id='WzWMX'></center></pre></bdo></b><th id='WzWMX'></th></span></q></dt></tr></i><div id='WzWMX'><tfoot id='WzWMX'></tfoot><dl id='WzWMX'><fieldset id='WzWMX'></fieldset></dl></div>

                        <bdo id='WzWMX'></bdo><ul id='WzWMX'></ul>
                      • <small id='WzWMX'></small><noframes id='WzWMX'>