Re: Help in SQL to balance the values ... ?

From: Robert Klemme <shortcutter_at_googlemail.com>
Date: Mon, 24 Dec 2012 15:27:35 +0100
Message-ID: <ajr72uFk1sdU1_at_mid.individual.net>



On 24.12.2012 15:13, Nova wrote:
> On Monday, December 24, 2012 2:48:40 PM UTC+3, Robert Klemme wrote:
>> On 12/24/2012 09:52 AM, Nova wrote:
>>
>>
>>
>>> I know it is difficult to explain, the idea is I have F that have
>>
>>> amount and I have M that have capacity, I want distribute the amount
>>
>>> to capacity depend on the links. I write the logic by subtract the
>>
>>> amount from capacity, in the last I have 10 capacity in M3 not used.
>>
>>>
>>
>>> I hope it clear.
>>
>>
>>
>> Not really. Are you talking about
>>
>> http://en.wikipedia.org/wiki/Knapsack_problem ?
>>
>>
>>
>> Cheers
>>
>>
>>
>> robert
>
> Sorry again.
>
> I make easier example and I draw it in a paper
>
>
> give in info as following:
> in table F_LINKTO_M
> F M
> ----------
> F1 M1
> F2 M1
> F2 M2
>
> in table F_V
> F F_V
> ----------
> F1 100
> F2 70
>
>
> in table M_V
> M M_V
> ----------
> M1 150
> M2 45
>
>
> explain to solve it:
> https://dl.dropbox.com/u/64041543/20121224.JPG
>
>
>
> In conclusion (Final Result)
> F1 = 0 remaining
> F2 = 0 remaining
> M1 = 0 empty
> M2 = 15 empty

Why is 0 sometimes empty and sometimes 15? What's the whole purpose of all this? Frankly, I find you are giving way too scarce information.

Btw, the fact that your algorithm takes multiple steps until some condition is reached *may* be an indication that this cannot be translated to vanilla SQL. If you have a formula which can calculate outputs from inputs without looping then you likely can translate it to SQL. Whether that formula exists I cannot tell as I do not have enough information (or am not interested enough to dig through this).

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Received on Mon Dec 24 2012 - 15:27:35 CET

Original text of this message