I want a sql query to calculate cumulative P/L on stock trading (FIFO based calculation).
Input table :