在SQL中有聚合运算符,如AVG、SUM、COUNT。为什么它没有乘法运算符?"MUL“之类的
我想知道,它是否存在于Oracle,MSSQL,MySQL?如果不是,是否有解决方法可以解决此问题?
发布于 2011-03-24 15:52:30
不能,但您可以使用数学:)
如果yourColumn
总是大于零:
select EXP(SUM(LOG(yourColumn))) As ColumnProduct from yourTable
发布于 2011-03-24 16:15:13
我发现Oracle的答案仍然缺失,所以它是这样的:
SQL> with yourTable as
2 ( select 1 yourColumn from dual union all
3 select 2 from dual union all
4 select 4 from dual union all
5 select 8 from dual
6 )
7 select EXP(SUM(LN(yourColumn))) As ColumnProduct from yourTable
8 /
COLUMNPRODUCT
-------------
64
1 row selected.
致以敬意,
罗伯。
发布于 2011-03-24 16:07:53
使用PostgreSQL,您可以创建自己的聚合函数,请参见http://www.postgresql.org/docs/8.2/interactive/sql-createaggregate.html
要在MySQL上创建聚合函数,需要构建一个.so (linux)或.dll (windows)文件。这里显示了一个示例:http://www.codeproject.com/KB/database/mygroupconcat.aspx
我对mssql和oracle不太确定,但我打赌他们也有创建自定义聚合的选项。
https://stackoverflow.com/questions/5416169
复制相似问题