Chain Multiplication on a column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • janet04
    New Member
    • Oct 2006
    • 1

    Chain Multiplication on a column

    Can someone point me out a function that return the multiplication of all row contents from a column?

    It should work like the sum() function, but instead of the summary.. it will return the chain multiplication result. Here is what I need it to do.

    x
    -------
    4
    2
    3
    7

    I need a function "multiply" so that when I issued "Select multiply(x) ...group by..." It would return 168 which is 4*2*3*7

    I need to do this in DB2, I checked the DB2 UDF, but looks like there is no simple way to create a customized column function like this.

    I'll be really appreciated if someone can help.
  • pulakesh dey
    New Member
    • Nov 2007
    • 2

    #2
    Originally posted by janet04
    Can someone point me out a function that return the multiplication of all row contents from a column?

    It should work like the sum() function, but instead of the summary.. it will return the chain multiplication result. Here is what I need it to do.

    x
    -------
    4
    2
    3
    7

    I need a function "multiply" so that when I issued "Select multiply(x) ...group by..." It would return 168 which is 4*2*3*7

    I need to do this in DB2, I checked the DB2 UDF, but looks like there is no simple way to create a customized column function like this.

    I'll be really appreciated if someone can help.

    --------------------------------------------
    Reply : select exp(sum(ln(val_ num))) from test_multiply;

    Comment

    • pulakesh dey
      New Member
      • Nov 2007
      • 2

      #3
      select exp(sum(ln(val_ num))) from test_multiply;

      It will solve your purpose

      Comment

      Working...