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字段上都要建立主键和索引。
用到某一字段的个数时,介意看看group by 的使用
不好意思,我表达错了,应该是如下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
from stat s,client c
where s.client_id=c.client_id
group by s.stat_idtry it.client_id、stat_id字段上都要建立主键和索引。
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