Re: Help in SQL to balance the values ... ?
From: joel garry <joel-garry_at_home.com>
Date: Thu, 27 Dec 2012 00:17:57 -0800 (PST)
Message-ID: <a5583551-8a0e-408a-9200-267c234d8660_at_r13g2000vbd.googlegroups.com>
On Dec 24, 11:59 am, Nova <nova1..._at_gmail.com> wrote:
> On Monday, December 24, 2012 6:10:12 PM UTC+3, Andreas Leitgeb wrote:
> > Nova <nova1..._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???!!!
Date: Thu, 27 Dec 2012 00:17:57 -0800 (PST)
Message-ID: <a5583551-8a0e-408a-9200-267c234d8660_at_r13g2000vbd.googlegroups.com>
On Dec 24, 11:59 am, Nova <nova1..._at_gmail.com> wrote:
> On Monday, December 24, 2012 6:10:12 PM UTC+3, Andreas Leitgeb wrote:
> > Nova <nova1..._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???!!!
Use the language you know first, then worry about doing it "right." Google for OracleŽ Database Java Developer's Guide and jdbc tutorials.
jg
-- _at_home.com is bogus. http://www.forbes.com/sites/timworstall/2012/06/25/rbsnatwest-computer-failure-fully-explained/Received on Thu Dec 27 2012 - 09:17:57 CET