--c列(第三列)的值固定是1,2,3吗? 如果是,就用:select id
,[1]=max(case c when 1 then b else '' end)
,[2]=max(case c when 2 then b else '' end)
,[3]=max(case c when 3 then b else '' end)
from 表
group by id

解决方案 »

  1.   


    --如果C列不固定,则用动态SQL
    declare @s varchar(8000)
    set @s=''
    select @s=@s+',['+cast(c as varchar)+'=max(case c when '+cast(c as varchar)+' then b else '''' end)'
    from 表
    group by c
    exec('select id'+@s+'
    from 表
    group by id
    ')
      

  2.   

    谢谢你的帮助
    c列(第三列)的值固定是1,2,3
    还有想在这个地方汇总,再次请教,如:
    id      1         2       3         4
    31321   25:48    11:42    27:55    64:55