Here is a hypothetical of what I am attempting to do:
Let’s say I have the closing value of two different stocks that I am tracking. I want to be able to return a table that has the stock name, today’s price and and how much EACH stock went up or down for the day.
ID | Stock_name | Stock_price | Date
1 | Apple | $600 | 2012-04-03
2 | Apple | $601 | 2012-04-04
3 | Google | $500 | 2012-04-03
4 | Google | $505 | 2012-04-04
Desired result:
Stock_name | todays_close | change_from_yesterday
Apple | $601 | 1
Google | $505 | 5
I’ve tried writing a query using LIMIT, but can’t manage to retrieve the latest 2 results for EACH stock_name, rather just the latest 2 results.
Another thing, I am trying not to use any date functions because my real data set has missing dates and I just want to compare to the last entry not the last date.
Any help with the specific MYSQL query to use would be mucho appreciated.
Thanks