0

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)

4

3 に答える 3

0

Got it - finally! rowid was a misnomer. Credit to Shawn Fox of Netezza Community for inspiration.

  Create table MYNEWTABLE as select * from
    (select *
            ,row_number() over (
                 partition by COL1, COL2 order by TIMESTAMP desc
                               ) row
       from MYTABLE 
    ) x
    WHERE x.row=1
    distribute on (COL1)
于 2011-10-24T10:50:17.627 に答える
0

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

于 2011-11-21T15:35:03.190 に答える
0

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

于 2016-04-03T14:19:21.800 に答える