0

I want count the result from table.

Table looks like this(row data),

enter image description here

Que is question and answer is Answer, and answer most have a value of 1 to 5, but it can vary depending on the question.(like 1 to 9)

The image above is only part and the question is from 1 to 13. The rows in the table repeat over and over again.

I'd like to know the percentage of answers to each question.

I try to count,

SELECT COUNT(*) FROM survey.surveys WHERE exhibition_id = 2 GROUP BY que;

But this is just count by que

How I can count it?


I want result like,

que | answer | count(answer)
 1  |   1    |    30
 1  |   2    |    27
 1  |   3    |    28
 1  |   4    |    31
 1  |   5    |    30
 2  |   1    |    17
 2  |   2    |    23
 2  |   3    |    31
 2  |   4    |    45
 2  |   5    |    29
3
  • 1
    "'d like to know the percentage of answers to each question." - what does this mean? Please provide example desired output results. Commented Nov 11, 2019 at 5:02
  • @Dai Attached to the question. Commented Nov 11, 2019 at 5:10
  • @Dai Sorry, It's simple of that. Thanks you for your answer Commented Nov 11, 2019 at 5:29

2 Answers 2

1

You should group by answers

SELECT COUNT(*) FROM survey.surveys WHERE exhibition_id = 2 GROUP BY answers

Sign up to request clarification or add additional context in comments.

4 Comments

But in that case, the result does not take into account the question.
You can add case when statement according your wish
Could you elaborate a little?
Sorry, It's simple of that. Thanks you for your answer
0

Try this

SELECT que,answer,count(answer) FROM survey.surveys WHERE exhibition_id = 2 GROUP by answer order by que asc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.