I have a table of questionnaire responses with a question ID, and a value that a user submitted.
I would like to get the counts of responses, and also the average for the whole question ID, so for example for question ID 1, there was a count of 3 for option 1, and acount of 2 for option 2, but the OVERALL average would be 7(sum of all optons) divided by 5(total submissions).
I can’t see how to do this with my group by, which does a total of resposnses grouped by questions ID and also option number.
Any pointers would be gratefully received!
Sample data would look like
questionID ResponseValue
1 5
1 5
1 6
2 7
2 7
2 7
2 3
My expected output would be
questionID responseValue countOfResponses questionAverage
1 5 2 5.3333
1 6 1 5.3333
2 3 1 6
2 7 3 6
Are you looking for something like…
On a per-option with overall total, I would pre-query the per question sum(value of responses), then group just on the question so you have that for all entries… then query again, but on a per question/option… So, in this case, you are getting the percentage of the total a given response represents, not an “average”… To ensure you get decimal precision, I’ve added * 1.0000 so it goes to a decimal forced result column and not just integer.