TSQL Challenge 39




TSQL Challenge 39 - Calculate Gross Profit by Item using FIFO method

This challenge is related to an inventory management application where your job is to calculate the profitability by item (cost vs sales) using First-In-First-Out (FIFO) processing method.

The inventory application has a table that stores the purchase information with the cost and another table that stores the sales details. You need to calculate the profit earned by each sales by calculating the differences between purchase cost and sales price. If an item is purchased more than once, it is assumed that the oldest stock will be sold first.