vba里面不一定要用SQL呀?
SQL中的求和函数SUM( )用于对数据求和,返回选取结果集中所有值的总和。语法如下:
SELECT SUM(column_name)
FROM table_name
单列求和
SELECT SUM(column_name) FROM table_name WHERE XX='……'"
单列条件求和
TEACHER表中查询年龄大于40岁的教师的工资总数。实例代码:
SELECT SUM(olumn_name) AS OLDSAL
FROM TEACHER
WHERE AGE>=40
多列求和
Select SUM(olumn_name) from table_name
where XX in ('一', '二', '三')
group by XX
去重复求和
select sum(k.b) from(select distinct a,b from test) k