I want to count the number of aircon and client under the same usr_id. Here's my resources:
clients_db
+---------+--------+ | clnt_id | usr_id | +---------+--------+ | 1 | a1 | +---------+--------+ | 2 | a1 | +---------+--------+ | 3 | a2 | +---------+--------+ | 4 | a1 | +---------+--------+ aircon_client_db
+---------+--------+---------+ | ac_id | usr_id | clnt_id | +---------+--------+---------+ | 1 | a1 | 1 | +---------+--------+---------+ | 2 | a2 | 2 | +---------+--------+---------+ | 3 | a2 | 1 | +---------+--------+---------+ | 4 | a2 | 3 | +---------+--------+---------+ According to the tables above. I want to count
- how many
clnt_idunder the sameusr_id - how many
ac_idunder the sameusr_id
So I coded:
select count(acdb.ac_id) as nAC, count(clnt.clnt_id) as nClnt from aircon_client_db acdb left join clients_db clnt on clnt.usr_sid=acdb.usr_sid where acdb.usr_sid='a1' I expect the answer as following:
- 3
- 1
But as I tested. My results are the same for both count - 4. Where did I wrong?