sql stored Update Value With value from the previous record in the same table

Asked

Viewed 26 times

0

I have a table with several repeated names sequenced by another column called id2 where each 1 of these records has a column with a quantity Example :

Name-Quantity-Value2-id2

teste1-1000-0-1

teste1-1100-100-2

teste1-1100-0-3

teste1-1100-0-4

teste1-1100-0-4

teste1-1100-0-4

That means there must be a Procedure where I have to fetch the previous "Quantity" add the current "Valor2" and save record after registration Any reply that might help I appreciate.

  • Does the table have a primary key? If so, what is the name of the column? In the example, the id2 column has repeated values; this is correct?

  • Not this correct, I published a perhaps clearer example below

  • It seems to me that there are contradictions in the objectives: "seek the previous Quantity to add the current Value2" with "add Quantitya Material + Quantitya - Value2". Could you check?

  • And when the value of id2 is 1, where there is no previous amount, what to do?

  • because this is also a problem in php I have something like that limiting the first query where it says that ...###############################Where ... ########= second query

  • Vide http://answall.com/questions/180842/como-escrever-um-store-procedure-que-usa-valores-da-linha-atual-e-da-anterior/181261

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.