不用子查询,用临时表,子查询的效率下降时必然的,你建立临时表试试
select billsale.prodcode,
sum(billsale.prod_number) as '已销售数量'
from storage, billsale
where billsale.prodcode = storage.prodcode
group by billsale.prodcode
Try this:
select storage.prodcode, sum(case when billsale.prod_number is null then 0 else billsale.prod_number end) as '已销售数量'
from storage left join billsale on billsale.prodcode=storage.prodcode
group by storage.prodcode
在数据建索引撒,或通过引擎优化顾问