SQL转换表查询

时间:2010-09-15 09:44:30

标签: sql sql-server-2008

我在转换一个看起来像这样的表

时遇到了问题
PropertyName | PropertyValue
---------------------------------
color    red
color    blue
size    big
size    small

进入这个:

Color  | Size
---------------------------------
red   big
red   small
blue   big
blue   small

我怎样才能做到这一点?提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您想要每种颜色和尺寸的排列吗?

SELECT color, size FROM 
(
select distinct  PropertyValue AS color
from YourTable
where PropertyName = 'color'
) T1
CROSS JOIN 
(
select distinct  PropertyValue AS size
from YourTable
where PropertyName = 'size'
) T2