I have problems trying to do some business logic for a client (web trading):
My client has a table (simplified) like this:
|| ID || OFFERED_PRODUCT_ID || DEMANDED_PRODUCT_ID ||
|| 01 || 34 || 45 ||
|| 01 || 34 || 16 ||
|| 01 || 45 || 57 ||
|| 01 || 47 || 57 ||
|| 01 || 57 || 63 ||
|| 01 || 16 || 20 ||
Now the application should show the largest trading chain, the trade chain is defined as the ratio within the proposed and required products.
These are the trade chains:
<34, 45, 57, 63 <34, 16, 20 <45, 57, 63 <47, 57, 63 <57, 63 <16, 20 </p>
I am trying to use C # to solve this problem, but given the amount of data this has become impossible. My colleague said that I recommend using recursion. I'm trying to figure out what he means, but I'm a client-side developer who doesn't know SQL.
I have done this:
select o.OFFERED_PRODUCT_ID, o.DEMANDED_PRODUCT_ID
from TRADES o
start with
o.DEMANDED_PRODUCT_ID = (SELECT MIN(o.DEMANDED_PRODUCT_ID) from TRADES)
connect by NOCYCLE prior o.DEMANDED_PRODUCT_ID = o.OFFERED_PRODUCT_ID;
( ). . . .
:
OFFERED_PRODUCT_ID DEMANDED_PRODUCT_ID
9920896475501851 59587794888502550724
59587794888502550724 13197303523502765990
13197303523502765990 54010274740204405159
54010274740204405159 14505831337880766413
14505831337880766413 89607128670993987443
89607128670993987443 8802863939059413452
8802863939059413452 7779127922701247342
7779127922701247342 3810800421539873909
3810800421539873909 12423373218147473557