SQL Server中具有重复名称的列的行

时间:2017-06-06 12:19:18

标签: sql sql-server

我有三个表ProductMasterProductParameter以及ParameterMaster

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

1 个答案:

答案 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中是这样的: