我試圖從SQL Server下面的代碼轉換爲Teradata的使用UNPIVOT邏輯:轉換的SQL Server UNPIVOT到TERADATA
insert into
IPData
select
1,
ProductCode || '|' ||
LocationCode || '|' ||
TimeCode || '|' ||
MeasureCode || '|' ||
cast(MeasureVal as varchar(12))
from
(
select
p.SubsectionCode ProductCode,
td_ss.LocationCode,
td_ss.TimeCode,
sum(
case
when td_ss.Life = 'C'
and td_ss.Seasonality = 'AW' then td_ss.DepotStockRetail
else 0
end) StkDep_AW_Act,
sum(
case
when td_ss.Life = 'C'
and td_ss.Seasonality = 'C' then td_ss.DepotStockRetail
else 0
end) StkDep_Cnt_Act,
sum(
case
when td_ss.Life = 'C'
and td_ss.Seasonality = 'SS' then td_ss.DepotStockRetail
else 0
end) StkDep_SS_Act,
sum(
case td_ss.Life
when 'T' then td_ss.DepotStockRetail
else 0
end) StkDep_Trm_Act,
sum(td_ss.DepotStockRetail) StkDep_Tot_Act
from
Stock td_ss
inner join
Product p
on td_ss.Kimball = p.CurrentKimball
and td_ss.SectArea = p.SectArea
and td_ss.SeasonID = p.SeasonID
group by
p.SubsectionCode,
td_ss.LocationCode,
td_ss.TimeCode)x
UNPIVOT
(MeasureVal for MeasureCode in
(StkDep_AW_Act, StkDep_Cnt_Act, StkDep_SS_Act, StkDep_Trm_Act, StkDep_Tot_Act)) as unpvt
where
MeasureVal <> 0;
我與UNPIVOT
部分掙扎。截至目前,我沒有任何表中的數據,因此有關UNPIVOT
的任何幫助都非常感謝。
這將是更容易理解,如果你提供的樣本數據和預期的結果。 –