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

From: Nova <nova1427_at_gmail.com>
Date: Mon, 24 Dec 2012 11:59:32 -0800 (PST)
Message-ID: <8385c836-ca38-4950-92e7-f923bafc6a85_at_googlegroups.com>



On Monday, December 24, 2012 6:10:12 PM UTC+3, Andreas Leitgeb wrote:
> Nova <nova1427_at_gmail.com> wrote:
>
> > 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
>
> >
>
> > In conclusion (Final Result)
>
> > F1 = 0 remaining
>
> > F2 = 0 remaining
>
> > M1 = 0 empty
>
> > M2 = 15 empty
>
>
>
> The drawing indeed helped to some degree.
>
>
>
> I'm wondering, if for the given example
>
> F1 = 0, F2 = 0, M1 = 15, M2 = 0
>
> would be a solution, too (as in F2 dumping
>
> to M2 first, and only the remainder to M1).
>
>
>
> Also, if for some reason, F2 paired with M1
>
> first (before F1 does), then the result would
>
> become F1 = 20, M1 = 0, F2 = 0, M2 = 45
>
> with no chance for F1 to dump its remaining 20 .
>
>
>
> So, I think, what you're really after is finding an
>
> arrangement that would get all Fs to 0. But that is
>
> an entirely non-trivial thing (maybe even NP-complete).

Thanks Mr. Andreas Leitgeb for replay and trying understand me.

> I'm wondering, if for the given example
>
> F1 = 0, F2 = 0, M1 = 15, M2 = 0

this is also fine

> Also, if for some reason, F2 paired with M1
>
> first (before F1 does), then the result would
>
> become F1 = 20, M1 = 0, F2 = 0, M2 = 45

you are right but if I start with F who has minimum paired with Ms, this will not happen (mostly) or get all possible and take minimum remaining.

In general, I will write the algorithm by my self. All I need how can I start?
this required recursive to get right answer but Oracle 10g not support. also this is very difficult to use START WITH and CONNECT BY in Oracle SQL (maybe not possible).

I can do it by Java language but I have no idea to use java in Oracle specially when I want to load all table to java and return the result as table to SQL.

I don't want help to write the algorithm but I need help to take the right way to start.

Any idea???!!! Received on Mon Dec 24 2012 - 20:59:32 CET

Original text of this message