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

解决方案 »

  1.   

    select c.client_id,count(s.stat_id)
    from stat s,client c
    where s.client_id=c.client_id
    group by s.stat_idtry it.client_id、stat_id字段上都要建立主键和索引。
      

  2.   

     用到某一字段的个数时,介意看看group by 的使用
      

  3.   

    不好意思,我表达错了,应该是如下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