I have 3 tables:
User (PK userid, ...)
Computer (PK computerid, FK userid, FK cpuid, ...)
CPU (PK cpuid, ...)
So, a user can have multiple computers, and each computer has exactly one CPU. Same cpu can appear in different computers.
I would like to get the number of computers and unique CPUs per user.
userid | Number of computers | Number of CPUs
---------------------------------------------
1 | 3 | 1 <- has 3 comps all with the same cpu
2 | 13 | 4 <- has 13 comps with 4 different cpus
...and so on
I dont have the problem with counting computers, but I stuck on counting the CPUs. Joining tables causes bad results because if the same cpu appears in more then one computer - count() returns total number of records as if they were not grouped...