Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no "product()" aggregate function in SQL? [duplicate]

When there are Sum(), min(), max(), avg(), count() functions, can someone help understand why there is no product() built-in function. And what will be the most efficient user-implementation of this aggregate function ?

Thanks, Trinity

like image 562
trinity Avatar asked Jan 26 '26 02:01

trinity


2 Answers

If you have exponential and log functions available, then:

PRODUCT(TheColumn) = EXP(SUM(LN(TheColumn)))
like image 148
dan04 Avatar answered Jan 28 '26 14:01

dan04


One can make a user-defined aggregate in SQL 2005 and up by using CLR. In Postgresql, you can do it in Postgres itself, likewise with Oracle

like image 42
Michael Buen Avatar answered Jan 28 '26 16:01

Michael Buen