insert into table2
select sum(数量) as 总数,sum(case when 状态一=1 and 状态二=1 then 数量 else 0 end) as 合格总数,sum(case when 状态一=0 or 状态二=0 then 数量 else 0 end) as 不合格总数
from table1 where 日期 between 日期1 and 日期2

解决方案 »

  1.   

    insert table2(总数,合格总数,不合格总数) 
    select sum(num),sum(case when (状态一=1 and 状态二=1) then  数量 else 0 end) as 合格总数,sum(case when (状态一=1 and 状态二=1) then 0 else 数量 end) as 不合格总数 from table1 where 日期 between @date1 and @date2
      

  2.   

    to: warning(爱就爱了) 状态1 或 状态2为0时为不合格 是“或”