本帖最后由 tebietebie 于 2012-10-19 23:04:50 编辑

解决方案 »

  1.   

    用case when 处理
    select
    max(case when cdxh=1 then pz end ) as pz1,
    max(case when cdxh=1 then fsts end ) as fsts1,
    max(case when cdxh=1 then yzsl   end ) as yzsl1,
    max(case when cdxh=2 then pz end ) as pz2,
    max(case when cdxh=2 then fsts end ) as fsts2,
    max(case when cdxh=2 then yzsl   end ) as yzsl2,
    max(case when cdxh=3 then pz end ) as pz3,
    max(case when cdxh=3 then fsts end ) as fsts3,
    max(case when cdxh=3 then yzsl   end ) as yzsl3,
    .................
    from tableName
    group by jh
      

  2.   

    select
    jh,
    max(case when cdxh=1 then pz end ) as pz1,
    max(case when cdxh=1 then fsts end ) as fsts1,
    max(case when cdxh=1 then yzsl   end ) as yzsl1,
    max(case when cdxh=2 then pz end ) as pz2,
    max(case when cdxh=2 then fsts end ) as fsts2,
    max(case when cdxh=2 then yzsl   end ) as yzsl2,
    max(case when cdxh=3 then pz end ) as pz3,
    max(case when cdxh=3 then fsts end ) as fsts3,
    max(case when cdxh=3 then yzsl   end ) as yzsl3,
    max(case when cdxh=4 then pz end ) as pz4,
    max(case when cdxh=4 then fsts end ) as fsts4,
    max(case when cdxh=4 then yzsl   end ) as yzsl4
    from tableName
    group by jh