title: AVG on same column by values in another column single sql query
body: <p>I want to find AVG on same column by values in different column single sql query.</p>
  
  <pre><code>table - question_rating
  review_id
  question_id
  rating
  </code></pre>
  
  <ul>
  <li>for each review there are multiple 16 questions and ratings.   </li>
  <li>question_id values are 1 to 16.</li>
  <li>rating values are from 1 to 5.</li>
  </ul>
  
  <p>I want to find avg of group of questions as</p>
  
  <p>Desired output-</p>
  
  <pre><code>qustion_id     rating
  -------------------------
  g1               4.4
  g2               3.7
  g3               5.6
  </code></pre>
  
  <p>g1 is group of questions (1,3)
  g2 is group of questions (2,6)
  g3 is group of questions (7,8)
  ....g8</p>
  
  <p>pseudo code-</p>
  
  <pre><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
  </code></pre>
  
  <p>I know it can be done by taking query separately but I want to know by single query.</p>
  
  <p>Or any easy way to find such output by php,etc.</p>