在SQL中, sum()函数怎么用?

如题所述

语句为:  

with temp1(col1) as

(select 1 col1

union all

select col1+1 col1

from

temp1

where col1+1<=20

)

select exp(sum(log(col1)))

from temp1;

扩展资料:

注意事项

sql中没有乘法函数,所以一般用:

logx+logy=logx*y

实现方式,先对记录取对数log(),然后sum聚合,最后exp,结果就是记录相乘的结果。

SUM函数的语法是:

SELECT SUM(expression )

FROM tables

WHERE predicates;

表达式可以是一个数值字段或公式。

例如,可能想知道合并全体员工的薪金总额美元以上,其薪酬是25,000/年

SELECT SUM(salary) as "Total Salary"

FROM employees

WHERE salary > 25000;

温馨提示:答案为网友推荐,仅供参考
相似回答