This is a question that requires logical reasoning, but come on.
How to do in SQL, it can be a function, a way to find out how many products I need to sell to reach the goal.
For example:
I sold a particular product and I need to know how many products need to be sold to get exact x real, and its value, of the product, has a minimum and maximum variation.
The amount of product must be the smallest possible until it reaches x real and each product can not have a value below 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 an output parameter: Input: Target, missing value, minimum value, maximum value. Output: Response
In case it is impossible to reach the goal, please state that based on the minimum and maximum values, it is not possible.