Question : count by columns

Hi Experts,

My problem is a lot easier to illustrate than to explain so here it goes:
This is how my table looks like:  A, B, C, D, E are departments

CustID | A | B | C | D | E |
123     | 1  | 1  | 2 |    |    |
456     |     | 1  | 3 |    |    |
789     | 1  |     |    |    |    |
012     | 2  |  1 | 4 | 8 | 8 |
234     |     |  2 | 3 | 4 | 5 |
345     |     | 5  | 9 |    |    |

Now, I need to count how many CustID is in only 1 dept, 2, dept, 3 dept etc..

This is how my result should look like
Count | Frequency
1        | 1
2        | 2
3        | 1
4        | 1
5        | 1

Thanks!

Answer : count by columns

Hi,

you can achieve the result with the attached query. "Table1" is the name of the table here.

Cheers,

Christian
1:
2:
3:
4:
5:
SELECT CustCount,Count(CustCount) AS CustIDsCount
FROM (SELECT (IIf(Nz(A,0)>0,1,0)+IIf(Nz(B,0)>0,1,0)+IIf(Nz(C,0)>0,1,0)+IIf(Nz(D,0)>0,1,0)+IIf(Nz(E,0)>0,1,0)) AS CustCount
FROM Table1)
GROUP BY CustCount
ORDER BY CustCount
Random Solutions  
 
programming4us programming4us