Find out how many products I need to sell before reaching the goal

Asked

Viewed 120 times

1

That’s a question that requires logical reasoning, but come on.

How to do in SQL can be function, a way to find out how many products I need to sell to reach the goal.

For example:

I sold a certain product and I need to know how many products need to be sold to get exact x real and its product value has minimum and maximum variation.

The quantity of product should be the smallest possible until it reaches real x and each product should not have a value lower than the minimum value and higher than the maximum value.

Practical example:

Meta: Vender R$ 90,00 reais

Vendi R$ 10,00 reais
Faltam R$ 80,00 reais

Valor minimo do produto: R$ 10,00 reais
Valor Maximo: R$ 20,00 reais

**Resposta**: Faltam  4 produtos de R$ 20,00 reais.

Another example:

Meta: Vender R$ 100,00 reais

Vendi R$ 10,00 reais
Faltam R$ 90,00 reais

Valor minimo do produto: R$ 10,00 reais
Valor Maximo: R$ 20,00 reais

**Resposta**: Faltam 4 produtos de R$ 20 reais e 1 produto de R$ 10,00 reais.

Another example:

Meta: vender R$ 19,00 reais

Vendi R$ 2,00 reais.
Faltam R$ 17,00 reais

Valor minimo do produto: R$ 2,00 reais
Valor Maximo: R$ 6,00 reais


**Resposta**: Faltam 2 produtos de R$ 6,00 reais e 2 produtos de R$ 2,5 reais.

The function will have 4 input parameters and one output: Input: Meta, missing value, minimum value, maximum value. Output: Answer

If it is impossible to reach the target state that on the basis of the minimum and maximum value it is not possible.

  • 1

    Depending on the number of products you can have thousands of different ways to achieve the goal. That’s right?

  • Have you developed any code ?

  • @Reginaldorigo I didn’t understand your comment.

  • @Gumball Not yet

  • @Leandro which bank?

  • 2

    Search by Backpack algorithm https://pt.wikipedia.org/wiki/Problema_da_backpack

  • @Sorack Sql Server

  • If you post your data model it becomes easier to help

  • @Daniel, one should prioritize the least amount of products possible. In the case of your example would be 1 product of 10 real.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.