本帖最后由 xjz6169 于 2010-12-15 17:21:11 编辑

解决方案 »

  1.   

    SQL> 
    SQL> with tablea as (
      2  select 'A0101' product_id, 1 property_id,'颜色' property_name, '红' property_values from dual union all
      3  select 'A0101' product_id, 2 property_id,'款式' property_name, '大号' property_values from dual union all
      4  select 'A0101' product_id, 3 property_id,'长度' property_name, '10' property_values from dual union all
      5  select 'A0102' product_id, 1 property_id,'长度' property_name, '20' property_values from dual
      6  )
      7  select product_id,
      8         max(decode(property_name, '颜色', property_values)),
      9         max(decode(property_name, '款式', property_values)),
     10         max(decode(property_name, '长度', property_values))
     11    from tablea
     12   group by product_id order by product_id
     13  /PRODUCT_ID MAX(DECODE(PROPERTY_NAME,'颜色 MAX(DECODE(PROPERTY_NAME,'款式 MAX(DECODE(PROPERTY_NAME,'长度
    ---------- ------------------------------ ------------------------------ ------------------------------
    A0101      红                             大号                           10
    A0102                                                                    20SQL> 
      

  2.   

    表:t_
    视图:v_
    存储过程:p_
    触发器:tr_
    主键:pk_
    外键:fk_
    索引:ix_
    局部变量:v_
    入口参数:i_
    ...
      

  3.   

    SQL> 
    SQL> with tablea as (
      2  select 'A0101' product_id, 1 property_id,'颜色' property_name, '红' property_values from dual union all
      3  select 'A0101' product_id, 2 property_id,'款式' property_name, '大号' property_values from dual union all
      4  select 'A0101' product_id, 3 property_id,'长度' property_name, '10' property_values from dual union all
      5  select 'A0102' product_id, 1 property_id,'长度' property_name, '20' property_values from dual
      6  )
      7  select product_id,
      8         max(decode(property_name, '颜色', property_values)),
      9         max(decode(property_name, '款式', property_values)),
     10         max(decode(property_name, '长度', property_values))
     11    from tablea
     12   group by product_id order by product_id
     13  /这个不错……
      

  4.   

    product_id property_id property_name property_values
    A0101 1 颜色 红
    A0101 2 款式 大号
    A0101 3 长度 10
    A0102 1 长度 20
    结果表:
    product_id 颜色 款式 长度
    A0101 红 大号 10
    A0102 20===>
    select product_id,
    max(case property_name when  '颜色'  then property_values) as 颜色,
    max(case property_name when  '款式'  then property_values) as 款式,
    max(case property_name when  '长度'  then property_values) as 长度
    from tb
    group by product_id
    order by product_id ;