Select 课号,主副消备,品名,规格名,max(单位),sum(上月初),sum(本月入) group by 课号,主副消备,品名,规格名
Select 课号,主副消备,品名,规格名,max(单位),sum(上月初),sum(本月入) from 表 group by 课号,主副消备,品名,规格名
select * from ( select 课号,主副消备,品名,规格名,sum(上月初) as 上月初,sum(本月入) as 本月入 from t group by 课号, 主副消备, 品名,规格名 )a, (select 课号,主副消备,品名,规格名,单位 from t where 单位<>'' and 单位 is not null ) b where a.课号=b.课号 and a.主副消备= b.主副消备 and a.品名=b.品名 and a.规格名=b.规格名
group by 课号,主副消备,品名,规格名
from 表
group by 课号,主副消备,品名,规格名
(
select 课号,主副消备,品名,规格名,sum(上月初) as 上月初,sum(本月入) as 本月入
from t
group by 课号, 主副消备, 品名,规格名
)a,
(select 课号,主副消备,品名,规格名,单位
from t
where 单位<>'' and 单位 is not null
) b
where a.课号=b.课号
and a.主副消备= b.主副消备
and a.品名=b.品名
and a.规格名=b.规格名