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

        <small id='3qVly'></small><noframes id='3qVly'>

        具有多列的 SQL Pivot

        SQL Pivot with multiple columns(具有多列的 SQL Pivot)
        <i id='DNAKH'><tr id='DNAKH'><dt id='DNAKH'><q id='DNAKH'><span id='DNAKH'><b id='DNAKH'><form id='DNAKH'><ins id='DNAKH'></ins><ul id='DNAKH'></ul><sub id='DNAKH'></sub></form><legend id='DNAKH'></legend><bdo id='DNAKH'><pre id='DNAKH'><center id='DNAKH'></center></pre></bdo></b><th id='DNAKH'></th></span></q></dt></tr></i><div id='DNAKH'><tfoot id='DNAKH'></tfoot><dl id='DNAKH'><fieldset id='DNAKH'></fieldset></dl></div>
        1. <legend id='DNAKH'><style id='DNAKH'><dir id='DNAKH'><q id='DNAKH'></q></dir></style></legend>
            <bdo id='DNAKH'></bdo><ul id='DNAKH'></ul>
              1. <small id='DNAKH'></small><noframes id='DNAKH'>

                  <tbody id='DNAKH'></tbody>
                • <tfoot id='DNAKH'></tfoot>

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

                  问题描述

                  需要有关 sql server 2008 中的 pivot 子句的帮助.我有一张包含此信息的表格:

                  Need help with the pivot clause in sql server 2008. I have a table with this info:

                  Weekno DayOfWeek FromTime ToTime1 2 10:00 14:001 3 10:00 14:002 3 08:00 13:002 4 09:00 13:002 5 14:00 22:003 1 06:00 13:003 4 06:00 13:003 5 14:00 22:00

                  Weekno    DayOfWeek     FromTime    ToTime
                  1         2             10:00       14:00
                  1         3             10:00       14:00
                  2         3             08:00       13:00
                  2         4             09:00       13:00
                  2         5             14:00       22:00
                  3         1             06:00       13:00
                  3         4             06:00       13:00
                  3         5             14:00       22:00
                  

                  我想把它转换成一个看起来像这样的表格:<前>周开始1结束1开始2结束2开始3结束3开始4结束4开始5结束5开始6结束6开始7结束71 10:00 14:00 10:00 14:002 08:00 13:00 09:00 13:00 14:00 22:003 06:00 13:00 06:00 13:00 14:00 22:00

                  I want to convert this into a table that looks like this:

                  Week    Start1    End1    Start2    End2    Start3    End3    Start4    End4    Start5    End5    Start6    End6    Start7    End7
                  1                         10:00     14:00   10:00     14:00
                  2                                           08:00     13:00   09:00     13:00   14:00     22:00
                  3       06:00     13:00                                       06:00     13:00   14:00     22:00
                  

                  有什么办法可以处理数据透视查询吗?请用一个例子来回答如何做.

                  Is there any way to do with a pivot query? Please write respond with an example on how to do it.

                  我很感激在这方面的任何帮助.提前致谢.

                  I appreciate any kind of help on this. Thanks in advance.

                  推荐答案

                  这是枢轴版本:

                  https://data.stackexchange.com/stackoverflow/query/7295/so3241450

                  -- SO3241450
                  
                  CREATE TABLE #SO3241450 (
                      Weekno int NOT NULL
                      ,DayOfWeek int NOT NULL
                      ,FromTime time NOT NULL
                      ,ToTime time NOT NULL
                  )
                  
                  INSERT INTO #SO3241450 VALUES
                  (1, 2, '10:00', '14:00')
                  ,(1, 3, '10:00', '14:00')
                  ,(2, 3, '08:00', '13:00')
                  ,(2, 4, '09:00', '13:00')
                  ,(2, 5, '14:00', '22:00')
                  ,(3, 1, '06:00', '13:00')
                  ,(3, 4, '06:00', '13:00')
                  ,(3, 5, '14:00', '22:00')
                  
                  ;WITH Base AS (
                      SELECT Weekno, DayOfWeek, FromTime AS [Start], ToTime AS [End]
                      FROM #SO3241450
                  )
                  ,norm AS (
                  SELECT Weekno, ColName + CONVERT(varchar, DayOfWeek) AS ColName, ColValue
                  FROM Base
                  UNPIVOT (ColValue FOR ColName IN ([Start], [End])) AS pvt
                  )
                  SELECT *
                  FROM norm
                  PIVOT (MIN(ColValue) FOR ColName IN ([Start1], [End1], [Start2], [End2], [Start3], [End3], [Start4], [End4], [Start5], [End5], [Start6], [End6], [Start7], [End7])) AS pvt
                  

                  这篇关于具有多列的 SQL Pivot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)

                  <small id='1eIJH'></small><noframes id='1eIJH'>

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

                        • <bdo id='1eIJH'></bdo><ul id='1eIJH'></ul>

                              <tbody id='1eIJH'></tbody>

                            <legend id='1eIJH'><style id='1eIJH'><dir id='1eIJH'><q id='1eIJH'></q></dir></style></legend>