我无法想象我的生活 -
select
*
from
(
select
Columnno
,dt
,Loans
,[Dials Attempted]
,dpl
,aband
,contact
,success
,conv
--,case when dt is not null then 1
from
data
) sourcetable
此查询将生成结果
我想要的结果将是
我尝试了一些事情,但它只是出错,帮助,我迷失了。提前致谢。
答案 0 :(得分:0)
这就是我最终做的事情
:
select
labels, [1],[2]
from(
select
*
,case when labels = 'Date' then 1
when labels = 'Loans' then 2
When labels = 'Dials Attempted' then 3
when labels ='DPL' then 4
when labels = 'Abandoned' then 5
when labels = 'Contacts' then 6
when labels = 'Success' then 7
when labels ='Conversion' then 8
end rownum
from
(
select
convert(varchar, Columnno ) Columnno
,convert(varchar, dt ) Date
,convert(varchar, Loans ) Loans
,convert(varchar, [Dials Attempted]) 'Dials Attempted'
,convert(varchar, dpl) DPL
,convert(varchar, aband) Abandoned
,convert(varchar, contact) Contacts
,convert(varchar, success) Success
,convert(varchar, conv) Conversion
--,case when dt is not null then 1
from
data
) sourcetable
unpivot ( [Data] for labels in (Date,Loans, [Dials Attempted], DPL, Abandoned, Contacts, Success, Conversion ) ) pivots) sourced
pivot( max(Data) for Columnno in ([1],[2])) pvt
order by rownum
这就是它产生的东西