没有聚合函数的 TSQL Pivot

我有一张这样的桌子...

I have a table like this...

CustomerID   DBColumnName   Data
--------------------------------------
1            FirstName      Joe
1            MiddleName     S
1            LastName       Smith
1            Date           12/12/2009
2            FirstName      Sam
2            MiddleName     S
2            LastName       Freddrick
2            Date           1/12/2009
3            FirstName      Jaime
3            MiddleName     S
3            LastName       Carol
3            Date           12/1/2009

我想要这个...

这可以使用 PIVOT 吗?

Is this possible using PIVOT?

CustomerID  FirstName   MiddleName          LastName        Date
----------------------------------------------------------------------
1           Joe             S               Smith           12/12/2009
2           Sam             S               Freddrick       1/12/2009
3           Jaime           S               Carol           12/1/2009

推荐答案

您可以使用 MAX 聚合,它仍然可以工作.一个值的最大值 = 该值..

You can use the MAX aggregate, it would still work. MAX of one value = that value..

在这种情况下,您也可以在 customerid 上自行加入 5 次,按每个表引用按 dbColumnName 过滤.可能效果会更好.

In this case, you could also self join 5 times on customerid, filter by dbColumnName per table reference. It may work out better.

相关文章