Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 17 Mar 2004 @ 10:11:56 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Function in teradata to calculate the Product???
 
From:   Mansfield, John

Thats a fair point. You would need to manage the signs separately, and the product calculation would become:

zeroifnull(exp(sum(ln(abs(nullifzero(col)))))) as n_product


Note this also accomodates zeros in this form.

The sign of the product is positive if the number of negative terms in the product is even, else the product is negative, so a further column of:

sum(
  case
     when col<0 then 1
     else 0
  end
) as n_neg,

to count the number of negative elements in col and then the sign itself should be:

-1*(n_neg mod 2) as signum,


so, finally, the product would be

signum * n_product as product


I hope that generalises the result to a more useful state.


Regards

John



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 23 Jun 2019