I have some data from an evaluation. Possible values are (1,2,3,4,5) and are stored in a table, for each question 1 column.
Table evaluation:
f1 f2 q3 ...
1 5 2
2 4 3
.
.
.
I want to generate for 2 columns 1 matrix:
How often is f1=1 when q3=1?
How often is f1=1 when q3=2?
...
How often is f1=5 when q3=5?
So it will be in my case a 5*5 matrix. How can I solve this with mysql properly?
My first (working) attempt is to brute force it with 25 unions like:
SELECT count(0) FROM evaluation where q3 = 1 and f2 = 1
union all
SELECT count(0) FROM evaluation where q3 = 1 and f2 = 2
union all
...
union all
SELECT count(0) FROM evaluation where q3 = 5 and f2 = 5
But how can it be done in a nice way?