品种

select distinct spid from sphwph where hw in ('HWI00000008','HWI00000003') and shl>0

批号

select distinct pihao,spid into #1 from sphwph where hw in ('HWI00000008','HWI00000003') and shl>0 order by spid

select spid from #1 group by spid having count(spid)>1

select spid from #1 group by spid having count(spid)>2

select spid from #1 group by spid having count(spid)>3

select spid from #1 group by spid having count(spid)>4

合起来的小批号

select spid,pihao,sum(shl) shl into #2 from sphwph where hw in ('HWI00000008','HWI00000003') and shl<>0 group by spid,pihao

select distinct pihao,spid from #2 where  shl>0 and shl<10  order by spid

散货品种有3146,批号共有4838,大于1的有1135,大于2的有372大于3的有124大于4的是37,小批号的1766