in reply to (OT) Dearest Monks - Mysql Question - Compare current insert record with last record inserted.
(SELECT stock FROM yourtable ORDER BY timestamp DESC LIMIT 1) as last_ +value
and use that to compute the difference for inserting.
But the fact that such a simple thing looks rather complicated in SQL points into another direction: design smell. Storing both original data (the stock prices) and derived data (the difference) in the same table makes that rather hard.
Maybe there's a better way, like storing the derived data in view and let mysql update it automatically.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: (OT) Dearest Monks - Mysql Question - Compare current insert record with last record inserted.
by jdlev (Scribe) on Nov 19, 2009 at 18:29 UTC | |
by keszler (Priest) on Nov 19, 2009 at 20:15 UTC | |
by jdlev (Scribe) on Nov 19, 2009 at 21:13 UTC | |
by keszler (Priest) on Nov 20, 2009 at 02:33 UTC |