T-SQL: Aggregate Values Multiplication Like SUM Aggregates Values Sum
Ever thought how to select multiplication from the database table the same way like ANSI sum:
select sum(myfield) from mytable
The following query shows how to do it. It uses one small mathematical trick that:
log(A * B) = log(A) + log(B)
Check it out !
select cast(exp(sum(log(my_field))) as int) as myresult from mytable
Sunday, November 30, 2003 1:36 AM