如何提高嵌套mysql的查询速度,比如这个?

如何提高嵌套mysql的查询速度,比如这个?,mysql,Mysql,在执行此类查询时,从mysql服务器检索快速响应有点困难: select distinct(products.id) as product_id,products.title as product_name, (select count(id) from stock where stock.available='0' and stock.product_id=products.id) as none, (select count(id) from stock where stock.availa

在执行此类查询时,从mysql服务器检索快速响应有点困难:

select distinct(products.id) as product_id,products.title as product_name, (select count(id) from stock where stock.available='0' and stock.product_id=products.id) as none,
(select count(id) from stock where stock.available='1' and stock.product_id=products.id) as available,
(select count(id) from stock where stock.available='2' and stock.product_id=products.id) as staged,
(select count(id) from stock where stock.available='3' and stock.product_id=products.id) as departed,
(select count(id) from stock where stock.available='4' and stock.product_id=products.id) as delivered
from products,stock where products.id=stock.product_id;
我想知道是否还有其他的查询方法可以提供更快的响应。Thanx:-)

类似这样的东西:

SELECT
  P.id as product_id,
  P.title as product_name,
  SUM(CASE WHEN S.available = 0 THEN 1 ELSE 0 END) as none,
  SUM(CASE WHEN S.available = 1 THEN 1 ELSE 0 END) as available,
  SUM(CASE WHEN S.available = 2 THEN 1 ELSE 0 END) as staged,
  SUM(CASE WHEN S.available = 3 THEN 1 ELSE 0 END) as departed,
  SUM(CASE WHEN S.available = 4 THEN 1 ELSE 0 END) as delivered 
FROM products P
      JOIN stock S
          ON P.id = S.product_id
    GROUP BY P.id,
             P.title

哦,我的哈姆雷特,这是对我的预先声明。第一次会用join,但是是的。。那边的那个人做得很好!Thanx mate:-)