SQL query to keep track of new orders or balance changes in old orders

I have a table with records similar to the following

order_id order_balance order_updated_date
34 400 Null
35 200 Null
36 100 Null

Once an order_id is inserted i.e. order_id = 34. A new record is not inserted(not an append) when the order_balance changes, the balance itself is updated in the same record. So say the balance for order_id=34 changes tomorrow to 300. When you look at the table tomorrow(lets say tomorrows date is 2020-02-01).

the recrd for order_id = 34 will look like:

order_id order_balance order_updated_date
34 300 2020-02-01

So I want to build a table that keeps track of the order_ids and the order_balances that are either newly inserted, or have had the balance change in the last day(or time period, could be hours,days,minutes,etc).



Read more here: https://stackoverflow.com/questions/68478263/sql-query-to-keep-track-of-new-orders-or-balance-changes-in-old-orders

Content Attribution

This content was originally published by NoStressZone at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: