sql 数据优化 union 代替or

select t.name,sum(t.SupplierCount) from (
select a.name,count(b.Supplier_Id) as SupplierCount
from yxs_administrators a,yxs_drugsbase_supplier b ,yxs_product c,yxs_supplies d,yxs_drugsbase e
where b.bstop=0  and a.adminid=b.editer and c.Supplier_Id=b.Supplier_Id and b.supplies_id=d.supplies_id and b.drugsbase_id=e.drugsbase_id
and b.agent_price=0
group by a.name
UNION all
select a.name,count(b.Supplier_Id) as SupplierCount
from yxs_administrators a,yxs_drugsbase_supplier b ,yxs_product c,yxs_supplies d,yxs_drugsbase e
where b.bstop=0  and a.adminid=b.editer and c.Supplier_Id=b.Supplier_Id and b.supplies_id=d.supplies_id and b.drugsbase_id=e.drugsbase_id
and suggested_price=0
group by a.name
) t
group by t.name

你可能感兴趣的:(UNION)