在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