I have a table name ITEM that consist of
+-------+-----------+--------------+ | Item | PrevValue | CurrentValue | +-------+-----------+--------------+ | ItemA | 2 | 10 | | ItemB | 1 | 2 | +-------+-----------+--------------+
And another table name PAYMENT that will require insert.
INSERT INTO PAYMENT(ID, Billing_Date, Due_Date, Value_Amount) VALUES (1,TO_DATE('23-JULY-2020','DD-MON-YYYY'), TO_DATE('21-AUGUST-2020','DD-MON-YYYY'), **CurValue - PrevValue** );
How do i correctly calculate the differences between PrevValue and CurValue in ITEM and insert them into PAYMENT?
Advertisement
Answer
The query will be, simply INSERT….SELECT:
INSERT INTO PAYMENT(ID, Billing_Date, Due_Date, Value_Amount) select 1,TO_DATE('23-JULY-2020','DD-MON-YYYY'), TO_DATE('21-AUGUST-2020','DD-MON-YYYY'), (CurValue - PrevValue) from ITEM where Item = '<Item_Name>';