I have a table with a set of questions as columns, the answers to the questions are either 1, 2 or 3 i.e.
id | q1 | q2 | q3 | q4 | q5
1 | 1 | 1 | 1 | 2 | 2
2 | 1 | 2 | 2 | 2 | 2
3 | 1 | 1 | 2 | 1 | 2
4 | 1 | 1 | 2 | 1 | 2
I need to work out how many 2's there are for each question, then identify the top 3 questions with the most 2's and say how many there are.
From my example above I would output
Top 3 questions with the most 2's
q5 = 4
q3 = 3
q4 = 2
Can I do this with sql alone?
Thanks
id | q1 | q2 | q3 | q4 | q5
1 | 1 | 1 | 1 | 2 | 2
2 | 1 | 2 | 2 | 2 | 2
3 | 1 | 1 | 2 | 1 | 2
4 | 1 | 1 | 2 | 1 | 2
I need to work out how many 2's there are for each question, then identify the top 3 questions with the most 2's and say how many there are.
From my example above I would output
Top 3 questions with the most 2's
q5 = 4
q3 = 3
q4 = 2
Can I do this with sql alone?
Thanks