I have two tables that basically record the maximum amount of weight in KG that a user can store in three different containers:
- dbo.Storage contains the most up to date values for a user (first screenshot)
- dbo.AuditStorage basically audits the change of these values (second screenshot)
The way that dbo.AuditStorage works is as follows (screenshot below):
The table is initially empty and when it first gets populated 3 rows will be inserted automatically (this is done by a trigger):
- The first row is inserted but only Max_Storage1 is populated while the remaining storages remain as NULL.
- Milliseconds after, another row is inserted. The Max_Storage1 value is persisted and Max_Storage2 is populated, while Max_Storage3 remains as NULL.
- Miliseconds after, another row is inserted. The Max_Storage1 and Max_Storage2 values are persisted and finally Max_Storage3 values are populated.
In the above screenshot we can see that a month later the user has decided to increase his Max_Storage1 from 50 to 100 and decrease his Max_Storage2 from 500 to 400. The same logic is applied here:
- First insert a row and update Max_Storage1 while the others Max_Storage_X remaing the same
- Then insert anoter row and update Max_Storage2
- Because Max_Storage3 remained the same, no row is inserted.
My goal is to be able to write a query that returns me a list of users where one of the Max_Storage_X values has increased while the other has decreased.
How can I achieve this please?