在 teradata 中生成增量序列号

Generate incremental sequence number in teradata

我假设会有 2 tables。

  1. scratch.data_table

  2. scratch.temp_table

scratch.data_table 将像 4000,4001,4002

一样以增量方式将字段之一设为 sequence_id

其他 table scratch.temp_table 将具有与 scratch.data_table 相同的其他列,但 sequence_id 列除外

scratch.temp_table 将有 5 条记录,我想从 scratch.data_table 中获取 sequence_id 中的 max,即 4002

从scratch.temp_table

的5条记录插入到同一个tablescratch.data_table

结果应该是这样的:

4000 | a | b | c
4001 | x | y | z
4002 | s | t | d
4003 | d | t | f   --> d|t|f is the records from scratch.temp_table and 4003 is the incremental value
4004 | d | g | h
4005 | g | t | h
4006 | y | u | i
4007 | y | y | t
select
    coalesce((select max(sequence_id) from data_table),0)
    + row_number() over (order by not_too_skewed_column_eg_PI)
 , t.*
from temp_table as t

或者您保留一个序列 table,其中每个 table

将当前最大值存储在一行中