SELECT count(rz_refer.refer_id) as refer,count(rz_client.client_id) as fault
FROM rz_refer,rz_client从两张表里面查询各自的记录总数,我这样查有什么问题?
我查出的结果总是refer和fault的值相等,应该怎么该?

解决方案 »

  1.   

    SELECT refer=(select count(refer_id) from rz_refer),count(client_id) as fault
    FROM rz_client
      

  2.   

    SELECT count(rz_refer.refer_id) as refer,(select count(rz_client.client_id) as fault from rz_client)
    FROM rz_refer
      

  3.   

    SELECT refer=(select count(1) from rz_refer where refer_id=a.refer_id) ,fault=(select count(1) from rz_client where client_id=b.client_id) 
    FROM rz_refer a inner join 
    rz_client b on a.id=b.id