是否有任何方法可以动态命名Netezza中的列列?在SSM中,我会使用一个存储的过程,但是我们的新Netezza Box限制了SP创建。使用案例语句,我可以使用"行号"对每月旋转每日总和,但是我希望新的列名称为实际的任意月份,而不是行号(month_id1包含row_number 1-12和相应的月id)。我认为策略性地放置了报价和一个子查询,但我无法正常工作。
select "DAY"
,sum(case when "ROW_NUMBER" = 1 then SUMOFCHGS else null end) as "1"
,sum(case when "ROW_NUMBER" = 2 then SUMOFCHGS else null end) as "2"
,sum(case when "ROW_NUMBER" = 3 then SUMOFCHGS else null end) as "3"
,sum(case when "ROW_NUMBER" = 4 then SUMOFCHGS else null end) as "4"
,sum(case when "ROW_NUMBER" = 5 then SUMOFCHGS else null end) as "5"
,sum(case when "ROW_NUMBER" = 6 then SUMOFCHGS else null end) as "6"
,sum(case when "ROW_NUMBER" = 7 then SUMOFCHGS else null end) as "7"
,sum(case when "ROW_NUMBER" = 8 then SUMOFCHGS else null end) as "8"
,sum(case when "ROW_NUMBER" = 9 then SUMOFCHGS else null end) as "9"
,sum(case when "ROW_NUMBER" = 10 then SUMOFCHGS else null end) as "10"
,sum(case when "ROW_NUMBER" = 11 then SUMOFCHGS else null end) as "11"
,sum(case when "ROW_NUMBER" = 12 then SUMOFCHGS else null end) as "12"
FROM DLYAMTS D
JOIN MONTH_ID1 M ON D.MONTHID = M.MONTHID
GROUP BY 1
ORDER BY 1
我可以在将来使用可变数量的列进行设想,但是我只是在寻找现在价值一年的列。
如果您想创建一个返回'表对象'的SP,我有相同的理解:不可能。但是,在我们的商店中,我们创建了基于一组论点的板条箱(永久)表。这些论点之一是"目标表名称"。在您的情况下,其他论点是:"输入表名称","列组",a" where子句","组织"列和"分布"列。
我希望这会有所帮助:)
lars