如何更改数据透视表中的列名?例如250 = emp1 [英] How do I change the column names in a pivot table? 250=emp1 for example
本文介绍了如何更改数据透视表中的列名?例如250 = emp1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
USE AdventureWorks2014;
SELECT *
FROM(
SELECT
VendorID,EmployeeID
来自Purchasing.PurchaseOrderHeader
)AS PUR
PIVOT
(
COUNT( EmployeeID)
FOR EmployeeID IN(250,251,256,257,260)
)AS PVT < br $> b $ b
我尝试了什么:
我不知道该怎么做试试我对SQL的新手。
USE AdventureWorks2014;
SELECT *
FROM(
SELECT
VendorID, EmployeeID
FROM Purchasing.PurchaseOrderHeader
) AS PUR
PIVOT
(
COUNT(EmployeeID)
FOR EmployeeID IN ("250", "251", "256", "257", "260")
) AS PVT
What I have tried:
I'm not sure what to try as I'm very new to SQL.
推荐答案
你应该真正阅读你找到示例代码的网页。
< a href =http://www.w3schools.com/sql/sql_alias.asp> SQL别名 [ ^ ]
Sql Server中的PIVOT和UNPIVOT | SqlHints.com [ ^ ]
使用PIVOT和UNPIVOT [ ^ ]
You should really read the web pages where you found your sample code.
SQL Aliases[^]
PIVOT and UNPIVOT in Sql Server | SqlHints.com[^]
Using PIVOT and UNPIVOT[^]
我想对这个问题添加一个扩展。
假设有一个表格会映射列具有实际名称的名称,例如在这种情况下。
250 | emp1 |
251 | emp2 |
251 | Johny |
252 |哈利|等等。
列名称应为(emp1,emp2,John,...)而不是(250,251,252,......)。
这是否有优雅的解决方案?
I want to add an extend to this question.
Let's say there is a table which will map the column names with actual names eg. in this case.
250 | emp1 |
251 | emp2 |
251 | Johny |
252 | Harry | and so on.
And the column names should be (emp1,emp2,John,...) and not (250,251,252,....).
Is there an elegant solution for this?
这篇关于如何更改数据透视表中的列名?例如250 = emp1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文