我的sql语句如下: 
select       
     client_id, 
     (select count(*) from stat where errorid<>0 and client_id=client.client_id) as staterrnum, 
     (select count(*) from stat where errorid=0  and client_id=client.client_id) as statnum 
from client   
查询起来非常慢,数据也不多啊,就几万行

解决方案 »

  1.   


    换个试试select a.client_id,b.num staterrnum,c.num statnum
    from client a,
    (select client_id,count(*) num from stat where errorid<>0 group by client_id) b,
    (select client_id,count(*) num from stat where errorid=0  group by client_id) c
    where a.client_id=b.client_id and a.client_id=c.client_id
      

  2.   

    呵,谢谢 david_xu322 按你的方法问题解决了,快了很多:)