I have some table that I want to get certain data information:
Product_code, qty, stock_before, stock_after, date
--------------------------------------------------------------
|product_code | qty | stock_before | stock_after | date |
--------------------------------------------------------------
| xpto1 | 0 | 1 | 1 | 2015-01-01 |
| xpto1 | 1 | 1 | 2 | 2015-02-01 |
| xpto1 | 2 | -1 | 1 | 2015-03-01 |
| xpto2 | 0 | 1 | 1 | 2015-01-01 |
| xpto2 | 1 | 1 | 2 | 2015-02-01 |
| xpto2 | 2 | -1 | 1 | 2015-03-01 |
I want to know to stock_before, for each product after 2015-01-01
So the result I want is
| xpto1 | 1 | 1 | 2 | 2015-02-01 |
| xpto2 | 1 | 1 | 2 | 2015-02-01 |
I am getting this:
| xpto1 | 1 | 1 | 2 | 2015-02-01 |
| xpto1 | 2 | -1 | 1 | 2015-03-01 |
| xpto2 | 1 | 1 | 2 | 2015-02-01 |
| xpto2 | 2 | -1 | 1 | 2015-03-01 |
Lets say that I only want the first record found for each product.