I need to subtract two rows in MySQL by using the most recent date from the previous date:
Starting table:
Stock Date Price
GOOG 2012-05-20 402
GOOG 2012-05-21 432
APPL 2012-05-20 553
APPL 2012-05-21 590
FB 2012-05-20 40
FB 2012-05-21 34
This is the result table:
Stock Date Price Change
GOOG 2012-05-21 30
APPL 2012-05-21 37
FB 2012-05-21 -6
Right now I just have two dates per company, but bonus upvotes if your query can handle any number of dates.
See Question&Answers more detail:os