While explaining some concepts over CTE, was asked with a cute question.. can we find the multiplication of rows , while we always concentrate on the SUM()
from a fresher. That gave me a thought! Is it ever possible with just an SQL. I was also considering the maximum number precision we can even support, since the product may be so huge.
Having said, we cant write our own aggregate function.(can we?) I am thinking is it ever possible with SQL only.
I thought of 2*3
is like adding 2 , 3 times to itself.. but when the set is huge.. I cant make it possible as it may be cumbersome.
Aonther possibility is log (a+b) = log a * log b;
and Anti logarithm
, gives you the result. This is what i managed to respond. For Oracle, I would have a function using EXECUTE IMMEDIATE
.
Can we actually multiply itself. Which will be more beautiful SQL-ly.. This is for pure learning experience.
See Question&Answers more detail:os