mysql sum()函数用法参考

发布时间:2020-09-01编辑:脚本学堂
本文介绍了mysql sum函数的用法,mysql sum函数求和的例子,需要的朋友参考下。

mysql中使用sum函数,对所有数据进行查询,并对其中的department字段值相同的值进行累加查询。

sql语句
 

select `department` , sum( `item_real` ) , sum( `item_budget` ) , sum( `tuisuan` ) from `budget_all` 
group by `department` 

仅仅对department=dd,dt进行求和:
 

select department,sum(item_real),sum(item_budget),sum(tuisuan) from budget_all 
where department='dt' or department='dd' group by department

求和原型:
 

select department,sum(item_real),sum(item_budget),sum(tuisuan) from tb group by department