select 订单号,sum(*) from tableName group by 订单号 不知道是不是你想要得
表结构?!select 生产订单号,sum(1号)+sum(2号)+...+sum(31号) as 生产总和 from 表 group by 生产订单号 where 生产的月份 between ... and ... and ...必须指出的是,从你的描述看,你的生产订单号并非主键,你的主键是:(生产订单号,生产的月份)
select 订单号,sum(每日的生产数量) from table group by 订单号
select 订单号,sum(*) as 总和 from tableName group by 订单号
group by 订单号
不知道是不是你想要得
from 表
group by 生产订单号
where 生产的月份 between ... and ...
and ...必须指出的是,从你的描述看,你的生产订单号并非主键,你的主键是:(生产订单号,生产的月份)
group by 订单号
from tableName
group by 订单号
主键是生产订单号+月份+年份,不过这不是重要的,每月的总和在表里有了,我要求的是根据每个订单号列出生产总和
如:
a号订单,1月生产100,2月生产100,总和200
b号订单,3月生产100,4月生产100,总和200 不能用between,因为月份不确定,订单是随机来的
sum(case when 月份=1 then 每日生产数量 else 0 end) as 月1,
sum(case when 月份=1 then 每日生产数量 else 0 end) as 月2,
...
from 表名
group by 定单号