我有一个表,每28天记录一次模式中所有表的记录计数。该表包含以下列: “TABLE_NAME”VARCHAR2(100 BYTE), “RECORD_COUNT”个号, “创建”日期
我想假脱机具有以下数据的日志文件:
感谢您的帮助。
答案 0 :(得分:2)
这样的事情应该这样做
SELECT table_name,
record_count,
prior_record_count,
record_count - prior_record_count diff
FROM (SELECT table_name,
record_count,
lag(record_count)
over (partition by table_name
order by created) prior_record_count,
rank()
over (partition by table_name
order by created) rnk
FROM <<name of table>>)
WHERE rnk = 1
答案 1 :(得分:1)
Oracle的LAG功能可以满足您的需求。它是一个返回前一行数据的分析函数。以下应该有效:
select
table_name,
record_count,
prev_record_count,
record_count - nvl(previous_record_count, 0) as difference
from (
select
table_name,
record_count,
lag(record_count) over (order by created) as prev_record_count
from
log_table
);