假設表:

目標表:

uj5u.com熱心網友回復:
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 機構
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/100623.html
標籤:基礎類
