Teradata:执行列的枢轴操作值插头
我在
有数百万的行,而4个teradata
上有一个表
(db.tab_unpivoted
)列
- - <代码> id ,<代码>周,sales
&amp; 利润
。以下是问题的小缩影。
为了插图,db.tab_unpivoted
就是这样:
://i.sstatic.net/n6dq6.png“ alt =“未分明表”>
我想pivot
此表。以下是我的代码:
SET SQL_STMT = ('CREATE TABLE DB.TAB_PIVOTED AS
( SELECT * FROM DB.TAB_UNPIVOTED
PIVOT
( SUM(Sales) AS Sales, SUM(Profits) AS Profits
FOR KW_Prefix IN (
'CW_1' AS CW_1,
'CW_2' AS CW_2,
'CW_3' AS CW_3
)
) AS dt
) WITH DATA;'
) ;
EXECUTE IMMEDIATE SQL_STMT;
奇怪的是,在关键
上,每次我得到不同的表db.tab_pivoted
,其中跨不同列的值互换。例如一次输出可以是:
但是,下次可能是一个结果,值互换,尽管profits
&amp; 销售
维护配对。在一个输出中,它们可以在cw_1
下,在另一个运行中,它可以在cw_3
下:
这个问题可能不会在小的小问题上复制数据,但是我的数据以数百万和cw
从1到52变化,我一直都在看到。
有人有一个想法吗?在枢纽
中,我犯了错误吗?
输入将非常尊敬。
更新:
我也尝试直接运行代码,而不是立即执行SQL_STMT
,但结果相同。
CREATE TABLE DB.TAB_PIVOTED AS
( SELECT * FROM DB.TAB_UNPIVOTED
PIVOT
( SUM(Sales) AS Sales, SUM(Profits) AS Profits
FOR KW_Prefix IN (
'CW_1' AS CW_1,
'CW_2' AS CW_2,
'CW_3' AS CW_3
)
) AS dt
) WITH DATA;
I am having a Table
(DB.TAB_UNPIVOTED
) on TeraData
having millions of rows, and 4 columns
- ID
, Week
, Sales
& Profits
. Here below is a small microcosm of the problem.
For sake of illustration DB.TAB_UNPIVOTED
is like this:
I want to PIVOT
this table. Following is my code:
SET SQL_STMT = ('CREATE TABLE DB.TAB_PIVOTED AS
( SELECT * FROM DB.TAB_UNPIVOTED
PIVOT
( SUM(Sales) AS Sales, SUM(Profits) AS Profits
FOR KW_Prefix IN (
'CW_1' AS CW_1,
'CW_2' AS CW_2,
'CW_3' AS CW_3
)
) AS dt
) WITH DATA;'
) ;
EXECUTE IMMEDIATE SQL_STMT;
The strange thing is that, on PIVOTING
, everytime I get a different table DB.TAB_PIVOTED
, where values across different columns are interchanged. For eg; one time the output can be:
But, next time, it could be a dfferent result, with values interchanged, though Profits
& Sales
maintain their pairing. In one output they could be under CW_1
, where as on another run, it could be under CW_3
:
This problem may not be reproduced on small data, but with my data in millions and CW
varing from 1 to 52, I see it all the time.
Does anyone have an idea, where in the pivoting
am I making the mistake?
Inputs would be very esteemed.
Update:
I tried running the code directly as well, instead of EXECUTE IMMEDIATE SQL_STMT
,but same strange results.
CREATE TABLE DB.TAB_PIVOTED AS
( SELECT * FROM DB.TAB_UNPIVOTED
PIVOT
( SUM(Sales) AS Sales, SUM(Profits) AS Profits
FOR KW_Prefix IN (
'CW_1' AS CW_1,
'CW_2' AS CW_2,
'CW_3' AS CW_3
)
) AS dt
) WITH DATA;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论