I’m very new to SQL and having trouble getting a SQL query to work.
I have a list of responses that contain the numbers 1 through 4 Example:
Question 1 contains the data Q1: 1,2,1,3,4,1,2,3,4,2
What I need to do is count how many 1’s and 2’s there are, total them and then average the number. Such as in the above example have a count that there are 6 1’s and 2’s total and divide that by the total number for a average. 6/10 = .6 (oh gosh I hope that made sense)
I have been trying this code but it is summing the numbers and then dividing by the total.
Select avg(q1) as avg
From db
Where q1 between 1 and 2
And call = 55817
Such as in the above example it’s doing this: 1+2+1+1+2+2=9/10 = .9 when again I need it to just “count” how many 1’s and 2’s there are.
For an SQLite specific solution, try this:
See it working online: sqlfiddle
For a more standard SQL solution, you might prefer this: