求和SQL

select t1.bom,t1.dates,sum(t2.counts),t1.customertype from test t1,test t2
where t1.dates >= dateadd(month,2,t2.dates) and t1.dates <= dateadd(month,12,t2.dates) and t1.bom = t2.bom and t1.customertype = t2.customertype and t1.customertype = '种别'
group by t1.dates,t1.bom,t1.customertype

你可能感兴趣的:(求和SQL)