Home > database > How to through the circular manner after each input data to the cumulative output
How to through the circular manner after each input data to the cumulative output
Time:09-22
There is a TABLE storage data is as follows:
How to through the circular manner will output after each input data accumulated, the logic: After each time the number of input processing QUANTITY, if it's the same ITEM_ID and CUSTOMER_ID, according to the result of TRANS_TYPE cumulative (plus or minus), Will not allow the accumulative, and every day the same ITEM_ID and CUSTOMER_ID there may be multiple records, the result is as follows (the results for the last column) :
CodePudding user response:
ORACLE's analysis function to deal with this is very simple, no cycle, cycle efficiency low instead
The select statement as follows, the update yourself to think about how to write
The select org_id, lines_id, item_id, customer_id, trans_type, quantity, transaction_date, The sum (quantity) over (partition by item_id, customer_id, trans_type order by lines_id) as inv_qty From the table.