Netezza LAST_VALUE 过滤器
我正在尝试创建一个 NETEZZA 表,该表仅包含特定键的最新记录 - 例如,想象一个表(MYTABLE)如下:
Col1 Col2 TIMESTAMP
xxxx xxxx 13:45
xxxx xxxx 13:46
xxxx yyyy 10:00
我想返回一个表,如下所示:
Col1 Col2 TIMESTAMP
xxxx xxxx 13:46
xxxx yyyy 10:00
我猜我需要一些代码of:
Create table MYNEWTABLE as
select *
from MYTABLE
WHERE rowid in
(
SELECT LAST_VALUE(rowid)
OVER (PARTITION BY COL1, COL2
ORDER BY TIMESTAMP)
FROM MYTABLE
)
ORDER BY COL1,COL2
distribute on (COL1)
但这实际上不起作用,有人可以建议吗? (具体如何通过 col1 / col2 分区内时间戳的最后一个值过滤表)
Am trying to create a NETEZZA table which has only the most recent records for a particular key - eg imagine a table (MYTABLE) as follows:
Col1 Col2 TIMESTAMP
xxxx xxxx 13:45
xxxx xxxx 13:46
xxxx yyyy 10:00
I would like to return a table as follows:
Col1 Col2 TIMESTAMP
xxxx xxxx 13:46
xxxx yyyy 10:00
I'm guessing I need some code along the lines of:
Create table MYNEWTABLE as
select *
from MYTABLE
WHERE rowid in
(
SELECT LAST_VALUE(rowid)
OVER (PARTITION BY COL1, COL2
ORDER BY TIMESTAMP)
FROM MYTABLE
)
ORDER BY COL1,COL2
distribute on (COL1)
However this isn't really working, can anyone please advise? (specifically how to filter the table by the last value of timestamp within the col1 / col2 partition)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您尝试实现 SCD2 ..我的意思是仅将新记录从源表插入到目标表,那么您可以执行左外连接并将数据插入到目标。
如果您的要求不同,请纠正我
if you are trying to implement SCD2 .. i mean inserting only new record to the target table from source table then you can do left outer join and insert the data to the target.
correct me if your requirement is different
明白了——终于! rowid 是一个用词不当。 感谢来自 Netezza 社区的 Shawn Fox 的灵感。
Got it - finally! rowid was a misnomer. Credit to Shawn Fox of Netezza Community for inspiration.
下面的查询应该可以正常工作。
创建表 TIMESTAMP_DATA_LATEST
作为
选择 Col1,Col2,MAX(Timestamp_val) AS Latest_TimeStamp
来自 TIMESTAMP_DATA
按第 1 列、第 2 列分组;
问候,
文克
The below query should work fine.
CREATE TABLE TIMESTAMP_DATA_LATEST
AS
SELECT Col1,Col2,MAX(Timestamp_val) AS Latest_TimeStamp
FROM TIMESTAMP_DATA
GROUP BY Col1,Col2;
Regards,
Venk