假设表:目标表:

解决方案 »

  1.   

    if object_id('Tempdb..#T') is not null
    drop table #t
    create table #t(机构 nvarchar(50),业务 nvarchar(50))
    insert #t values
    (1,'a'),(2,'a'),(2,'b'),(3,'c'),(3,'b'),(4,'c'),(4,'b'),(5,'b')
    select * from #t
    select 机构,
     max(case when 业务='a' then '' else 0 end) a,
     max(case when 业务='b' then '' else 0 end) b,
     max(case when 业务='c' then '' else 0 end) c
    from  #t
    group by 机构