-1

table inventorys

stock id cost       date   id   Type
ABC     1000.00 2018-01-01  1   BEGINING_QTY
ABC     2000.00 2018-02-01  2   PURCHASE
ABC     3000.00 2018-02-03  3   PURCHASE
BBB     1000.00 2018-01-01  4   BEGINING_QTY
BBB    20000.00 2018-10-01  5   PURCHASE
BBB    3000.00  2018-10-05  6   PURCHASE

i will get data like this

stock_id   cost     date
ABC        3000      2018-02-03
BBB        3000      2018-10-05
Madhur Bhaiya
  • 27,326
  • 10
  • 44
  • 54

1 Answers1

0

This can be helpful.

SELECT inventorys.stock_id,inventorys.date,inventorys.cost
FROM inventorys inventorys
INNER JOIN ( SELECT stock_id, MAX(date) FROM inventorys GROUP BY stock_id ) inv_temp ON inv_temp.date=inventorys.date AND inv_temp.stock_id=inventorys.stock_id
Valerian Pereira
  • 705
  • 1
  • 6
  • 16
Subin Chalil
  • 3,368
  • 2
  • 22
  • 38