SQL语句执行太慢,怎么优化?

2024-11-23 12:13:18
推荐回答(4个)
回答1:

不用子查询,用临时表,子查询的效率下降时必然的,你建立临时表试试

回答2:

select billsale.prodcode,
sum(billsale.prod_number) as '已销售数量'
from storage, billsale
where billsale.prodcode = storage.prodcode
group by billsale.prodcode

回答3:

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

回答4:

在数据建索引撒,或通过引擎优化顾问