使用3个或更多列的SQL查询数据透视表 [英] sql query pivot using 3 or more columns
问题描述
我有5列
i have 5 columns
equpname
pm_Date
ActDate
doneby
reviewby
使用此
http://sqlhints.com/2014/03/08/how-to-get-quarterly-data-in-sql-server/ [ ^ ]
我已经生成了一些日期,但如何以下面的格式获取日期请帮助
equpname | q1 | q2 | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pmdate | 行动日期 | 由 | 完成审核 | 行动日期 | 由 | 完成 > / table>
equpname | q1 | q2 | ||||||
---|---|---|---|---|---|---|---|---|
pmdate | act date | done by | reviewed by | pmdate | act date | done by | reviewed by |
推荐答案
我强烈建议您阅读:在SQL Server 2005中透视两列或更多列 [ ^ ]
相关文章的作者声明你可以转动多个列,但是你必须在透视列中添加额外的信息。
在你的情况下它会是这样的:
I'd strongly recommend to read this: Pivot two or more columns in SQL Server 2005[^]
The author of related article states that you're able to pivot more then one column, but you have to add extra info into pivoted column.
In your case it would be something like this:
equpname q1_pm_Date q1_ActDate q1_doneby q1_reviewby q2_pm_Date q2_ActDate q2_doneby q2_reviewby
知道了吗?
要实现您想要达到的目标,您需要使用报告工具,它提供显示多个标题的功能。
您可以在 CP知识库中找到更多内容[< a href =http://www.codeproject.com/search.aspx?q=pivot+multiple+columns+tag%3asqltarget =_ b lanktitle =新窗口> ^ ]网站。
Got it?
To achieve what you want to achieve, you need to use reporting tool, which provides functionality to display multiple headers.
More you'll find at CP Knowledge Base[^] site.
这篇关于使用3个或更多列的SQL查询数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!