Home > database >  How to deal with the next line of data using a line of difference
How to deal with the next line of data using a line of difference

Time:10-24

Documents date in stock inventory quantity dispatch quantity inventory count
The 2020-1-1 A, 50, 95 0
The 2020-2-1 A, 40, 95 0
The 2020-3-1 A, 20 95 15
A 10, 95 to 10 2020-4-1

How can write SQL the inventory of the effects of a column of
According to the date of documents the beginning of the earliest deductions
The delivery is according to the inventory summary, warehousing is according to the date of inventory and summary

CodePudding user response:

The first line the - 45 saves - 45-5-5, query the case when the inventory & lt; 0 then 0 elese inventory is bad?

CodePudding user response:

New version before a line after a reference line can use LEAD/LAG, the old version can use variables + update to get the temporary table
  • Related