2010-09-15 73 views
1

我得到了转化的表看起来像这样SQL转换表查询

PropertyName | PropertyValue 
--------------------------------- 
color red 
color blue 
size big 
size small 

到这是一个问题:

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

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

回答

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 
+0

好的,这是一个开始。非常感谢。但是有没有办法,自动为所有PropertyNames和-Values做?我的意思是不必为每个属性名写一个交叉连接? – fancyPants 2010-09-15 10:20:20

+0

不在标准SQL中。你能用你正在使用的RDBMS标记你的问题吗? – 2010-09-15 10:23:05

+0

然后我想我必须忍受它。再次感谢。 – fancyPants 2010-09-15 10:26:57