如何从每日级别数据中仅获取变更记录?

时间:2019-01-11 20:49:44

标签: oracle

我有大量的库存数据。我们正在跟踪每天的库存量。我的目的是获取仅在金额更改时才记录的查询:

示例:

enter image description here

所需结果:

enter image description here

1 个答案:

答案 0 :(得分:1)

使用子查询尝试以下查询:

Select date_id, product,warehouse,amount
From 
(
  Select 
      date_id, product, warehouse, amount, 
      lag(amount) over (partition by product, warehouse order by date_id) amount_prev
  From TABLENAME
) x
Where amount <> amount_prev