select company,sum(factoryprice)+sum(wholeprice) +sum(wholeprice) as num,time (select case when factoryprice >0 then 1 else 0 end as factoryprice, case when wholeprice >0 then 1 else 0 end as wholeprice, case when retailprice>0 then 1 else 0 end as retailprice, company,time from tablename) as t group by company,time
select company,sum(factoryprice)+sum(wholeprice)
+sum(wholeprice) as num,time (select case when factoryprice >0 then 1 else 0 end as factoryprice,
case when wholeprice >0 then 1 else 0 end as wholeprice,
case when retailprice>0 then 1 else 0 end as retailprice,
company,time from tablename) as t
group by company,time
price>0的个数 (FactoryPrice +WholePrice+ RetailPrice) 得到的
比如gong 5 2014 这个5就是尿素有3个>0 碳铵1个 普通钙1个