I have a little "game". I have the following Oracle Table (a view more exactly), where I have the values for my columns id, cod, val, t1, tall and I need to calculate v1,v2,v3,v1a,v2a,v3a.

ID   Cod   Val   T1   Tall |  V1   V2   V3 | V1a   V2a   V3a |
1    R1    99    179  301  |  99           |                 |
2    R2    125   179  301  |       80      |       45        |
3    R2    77    179  301  |        ?      |       77        |

The rules of the "game" are:

  1. I have my values from ID, COD, VAL, T1 and Tall and I must calculate V1,2,3,V1a,2a,3a.
  2. v1+v2+v3(on all three rows)=T1
  3. v1+v2+v3+v1a+v2a+v3a=Tall
  4. On each row, I must put part of VAL first in columns v1-2-3, until I reach T1 (*1) and after that, I must put the remaining values from VAL to v1a-2a-3a until I reach the value from Tall (*2)
  5. I must put the value according to the COD, VAL with R1 as COD only in column V1 or V1a, R2 in V2 or V2a and R3 on V3 or V3a

I'll make another example with same numbers:

ID   Cod   Val   T1   Tall |  V1   V2   V3 | V1a   V2a   V3a |
1    R1    99    179  301  |  99           |                 |
2    R2    77    179  301  |       77      |                 |
3    R2    125   179  301  |       3       |       122       |

The question is - how can I know - when I am on the row 3, when I am on the column V2 (marked with ?) that I've added 80 on V2 and I allready have 179 (T1) on V1-2-3? The same question for the second example, how can I know that I have the sum of 176 from T1 and put only 3 on V2 and the rest (of 122) on v2a?

Please, consider it like a game, but the usefulness of this "game" it's very important for I script I need. So, you can give me your "minus" if you think that this is not a "problem" for this forum but I am in a need for an answer to this. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.