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:

enter image description here

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:

enter image description here

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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -