我有一个审计表,它记录了每个字段的值以及更改的时间戳。我想编写一个查询,该查询采用列的起始值,查看该值何时更改,并在同一记录中为我提供更改的时间戳。
这可能吗?
我尝试使用 LEAD() 函数进行探索,然后使用分层查询到目前为止无济于事。
这是我用 LEAD() 尝试过的。
SELECT provider_id,
sub_address_id,
flag_practice,
flag_mailing,
last_updated_db_date,
LEAD (
flag_practice)
OVER (PARTITION BY provider_id, sub_provider_address_id
ORDER BY last_updated_db_date ASC)
next_flag_practice,
LEAD (
flag_mailing)
OVER (PARTITION BY provider_id, sub_provider_address_id
ORDER BY last_updated_db_date ASC)
next_flag_mailing,
LEAD (
last_updated_db_date)
OVER (
PARTITION BY provider_id, sub_provider_address_id
ORDER BY last_updated_db_date ASC)
next_practice_update_date, --this does not necessarily produce the next update date of the PRACTICE field but rather any update (which i dont want)
RANK ()
OVER (PARTITION BY provider_id, sub_provider_address_id
ORDER BY last_updated_db_date ASC)
rnk -- thought it might help in some form later, haven't quite seen how yet
FROM aud_address
ORDER BY provider_id, sub_provider_address_id, rnk;