SQL Server Query to find best quantity division

Job ID: 32195372

Budget: $10 – $30 USD

I have a table that stores products of varying pack sizes. I want to do a select query to choose the best combinations of product to select the minimum amount of products for a given order.

The query must check pack size and quantity available to produce the best results.

Pid Packsize Quantity
1 5 4
2 3 4
3 2 4
4 1 4
Examples Order = 5

Pid Quantity
1 1

Examples Order = 7

Pid Quantity
1 1
3 1

Out of stock examples

Pid Packsize Quantity
1 5 0
2 3 4
3 2 0
4 1 4

Examples Order = 5

Pid Quantity
2 1
3 1

Examples Order = 7

Pid Quantity
2 2
4 1