sql根据ID 合并计算

select 药品ID,Max(商品名) as '商品名',Sum(上月末库存) as '上月末库存',Sum(本月采购数) as '本月采购数',Sum(本月销售数) as '本月销售数',Sum(库存) as '库存',Max(盘点时间) as '盘点时间' from 历史盘点表  group by 药品ID





select 药品ID,Max(商品名) as '商品名',Sum(上月末库存) as '上月末库存',Sum(本月采购数) as '本月采购数',Sum(本月销售数) as '本月销售数',Sum(库存) as '库存',Max(盘点时间) as '盘点时间' from 历史盘点表   where  盘点时间=" + textBox1.Text + "and 库存>'0'  group by 药品ID



Max(商品名) as '商品名'  ;是取最大的 从商品名

Sum(本月销售数) as '本月销售数'  ;是计算总和


winform代码
桂ICP备16004754号