Philippe lelynx
phpons at gmail.com
Thu Oct 11 14:32:00 CDT 2012
thank you, John, I understand what you mean, I will go this way. Regards, Philippe 2012/10/11 jwcolby <jwcolby at colbyconsulting.com> > One way would be to put a FK in the record which holds the PK of the > previously stored record for a given stock. That requires looking up the > previous record before updating the new record but it then gives you a dead > simple inner join to get the difference between the current and the > previous. Just join the table on itself using the PK and that FK. > > It is called a "single linked list" when done in code. > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > > On 10/11/2012 1:15 PM, Philippe lelynx wrote: > >> Hi all, >> >> I need your help regarding a sql query. >> >> I have a table, say STOCK(stock_date, stock_qty) >> >> It records the stock level at the end of each day. >> >> I need to calculate, for each day, the stock variation. >> >> i.e for the day n => stock(n) - stock(n-1) >> >> How would you build such a query?? >> >> Regards, >> >> Philippe Pons >> >> > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/accessd<http://databaseadvisors.com/mailman/listinfo/accessd> > Website: http://www.databaseadvisors.**com<http://www.databaseadvisors.com> >