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  
  •  Terminal Services Installation Fails on Windows Server 2008
  •  Where and how can i use silent switches for a MSI file in the group policy.
  •  Error "windows cannot access the specified device path, or file. you may not have the appropriate permissions to access them"
  •  The transaction log for database 'mydatabase' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
  •  Windows 2008: When they say "CPUs supported", are they talking CPU sockets or CPU cores?
  •  How to clear @@error or general error flag in T-SQL
  •  What is the MS Access 2007 version of this code?
  •  Using Server.Mappath to get a file from a virtual directory
  •  How to prevent the auto update within an Acces 2007 template
  •  How to Take ownership of folder and all subdirectories and files?
  •  
    programming4us programming4us