Crusty
Lifer
I have a table named prices with 2 columns, date and price;
Sample data
2006-10-31,5.00
2006-10-30,4.75
2006-10-29,5.50
2006-10-28,4.25
I need to get a list of price differences ie.
5.00 - 4.75
4.75 - 5.50
5.50 - 4.25
I can't for the life of me figure out how to offset the join by 1 day so that I can subtract the 2 fields.
The only way I have figured out how to do it is really slow... which can not be.
SELECT p1 - p2 FROM (SELECT prices1.date AS p1d, prices2.date AS p2d,prices1.price AS p1, prices2.price AS p2 FROM prices prices1, prices prices2) temp WHERE DATE_SUB(temp.p1d, INTERVAL 1 DAY) = temp.p2d;
That's slow and ugly 🙁
Any ideas?
this is on a mySQL 5.0.22 server
Sample data
2006-10-31,5.00
2006-10-30,4.75
2006-10-29,5.50
2006-10-28,4.25
I need to get a list of price differences ie.
5.00 - 4.75
4.75 - 5.50
5.50 - 4.25
I can't for the life of me figure out how to offset the join by 1 day so that I can subtract the 2 fields.
The only way I have figured out how to do it is really slow... which can not be.
SELECT p1 - p2 FROM (SELECT prices1.date AS p1d, prices2.date AS p2d,prices1.price AS p1, prices2.price AS p2 FROM prices prices1, prices prices2) temp WHERE DATE_SUB(temp.p1d, INTERVAL 1 DAY) = temp.p2d;
That's slow and ugly 🙁
Any ideas?
this is on a mySQL 5.0.22 server