2017-06-06 52 views
-1

我有三个表ProductMasterProductParameterParameterMasterSQL Server中列名重复的行

ProductMaster包含多个产品,每个产品有多个参数,其值存储在productparameter中。

现在我需要ProductParameter值作为列。我正在使用数据透视表,但我只能获得一个产品价值。我要像

ProductID Name   ParameterValue1 ParameterValue2 
-------------------------------------------------------------- 
    1   Product-1 test    test2 
    2   Product-  anothervalue  another value2 

表中的所有产品的清单是如下

参数主

ParameterID 
Name 

ProductParameter

ProductParameterID 
ProductID 
ParameterID 
Value 

ProductMaster

ProductID 
Name 
+0

后的样本数据和预期的输出,帮助您更好 –

回答

0
select pp.ProductParameterId, pp.ProductID, pp.ParameterID, pp.value 
    from ParameterMaster pm, ProductParameter pp, ProductMaster p 
    where p.name = pm.name 
    and 
    pp.ProductId = p.ProductId 
    and 
    pm.ParameterId = pp.ParameterId; 

在oracle中是这样的:

+3

[不良习惯踢:使用旧样式的JOIN(http://sqlblog.com/blogs/aaron_bertrand /archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx) - 旧式*逗号分隔的表*样式列表被替换为* proper * ANSI'在ANSI - ** 92 ** SQL标准(** 25年**之前!)中使用JOIN'语法,不鼓励使用它 –

+0

marc_s感谢您的建议 –