Finding the first item amongst a series of items in MySQL -
i have following data in mysql db , need find occurrence of first buy / sell (see status column) along corresponding stock , corresponding price
for example have following data in table:
i have highlighted occurrence of first buy , sell in yellow aapl , in orange msft better understanding.
the query in mysql should give me following result:
you try
select current.date, current.stock, current.price, current.status <your table> current left join <your table> previous on previous.date = (select max(t.date) <your table> t t.date < current.date) current.status <> previous.status or previous.status null order current.date
Comments
Post a Comment