I want to find AVG on same column by values in different column single sql query.
table - question_rating
review_id
question_id
rating
- for each review there are multiple 16 questions and ratings.
- question_id values are 1 to 16.
- rating values are from 1 to 5.
I want to find avg of group of questions as
Desired output-
qustion_id rating
-------------------------
g1 4.4
g2 3.7
g3 5.6
g1 is group of questions (1,3) g2 is group of questions (2,6) g3 is group of questions (7,8) ....g8
pseudo code-
select (if(qustion=1 and question=3) as g1,
if(qustion=2 and question=6) as g2), ..
)avg(rating of respective group) from question_rating
I know it can be done by taking query separately but I want to know by single query.
Or any easy way to find such output by php,etc.