Domanda

Ho una tabella come questa:

Name    State       Amount
------------------------------
Pump 1  Present     339
Pump 1  Optimized   88

Voglio trasposizione in Fa qualcosa di simile:

Pump 1  Present     339 Optimized   88

Come posso fare questo con MS SQL 2000? Ho provato a cercare una soluzione, ma non ho trovato il massimo un raccordo.

È stato utile?

Soluzione

declare @t table(Name    varchar(10), State       varchar(10), Amount int)
insert into @t
select 'Pump 1',  'Present',     339  union all
select 'Pump 1',  'Optimized',   88 

select name,
max(case when state='Present' then 'Present' end),
max(case when state='Present' then Amount end),
max(case when state='Optimized' then 'Optimized' end),
max(case when state='Optimized' then Amount end)
from @t
group by name
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top