I have 3 categorical columns with the same value ranges: 0/1 and NULL.
The columns in SQL:
Column1 | Column2 | Column3 |
---|---|---|
0 | 1 | 1 |
0 | 1 | 0 |
1 | NULL | 1 |
NULL | 0 | 1 |
I want the counts per category like this:
Categories | Cnt_Col1 | Cnt_Col2 | Cnt_Col3 |
---|---|---|---|
0 | 2 | 1 | 1 |
1 | 1 | 2 | 3 |
NULL | 1 | 1 | 0 |
Does anybody know how this is possible in SQL? The following query doesn't give the expected result:
Select count(*), column1, column2, column3 from table group by column1, column2, column3