【发布时间】:2017-11-24 07:26:17
【问题描述】:
我正在尝试使用 UNPIVOT 逻辑将以下代码从 SQL Server 转换为 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 的帮助。
【问题讨论】:
-
如果您提供了样本数据和期望的结果,会更容易理解。
标签: sql-server teradata unpivot