title: Avg by Group in SQL
body: <p>I have query and I want the average of each <code>Place_id</code>, but my query is returning a wrong output.</p>
  
  <p>Is there something wrong in my query?</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT DISTINCT 
      place_id,
      SUM(fc.[main_percent_score]) aVG,
      CASE 
         WHEN fc.[main_percent_score] &gt;= 0.00 AND fc.[main_percent_score] &lt;= 0.99 
            THEN '0'
         WHEN fc.[main_percent_score] &gt; 1.0 AND fc.[main_percent_score] &lt;= 10.0 
            THEN '10'
         WHEN fc.[main_percent_score]  &gt; 10.0 and fc.[main_percent_score]  &lt;= 20.0 then  '20'
      when fc.[main_percent_score]  &gt;20.0 and fc.[main_percent_score]  &lt;= 30.0 then  '30'
      when fc.[main_percent_score]  &gt;30.0 and fc.[main_percent_score]  &lt;= 40.0 then  '40'
      when fc.[main_percent_score]  &gt;40.0 and fc.[main_percent_score]  &lt;= 50.0 then  '50'
      when fc.[main_percent_score]  &gt;50.0 and fc.[main_percent_score]  &lt;= 60.0 then  '60'
      when fc.[main_percent_score]  &gt;60.0 and fc.[main_percent_score]  &lt;= 70.0 then  '70'
      when fc.[main_percent_score]  &gt;70.0 and fc.[main_percent_score]  &lt;= 80.0 then  '80'
      when fc.[main_percent_score]  &gt;80.0 and fc.[main_percent_score]  &lt;= 90.0 then  '90'
      when fc.[main_percent_score]  &gt;90.0 and fc.[main_percent_score]  &lt;= 100.0 then  '100'
      end "PerTest" 
  from [final scoring based on main] fc
  group by case
    when fc.[main_percent_score]  &gt;= 0.00 and fc.[main_percent_score]  &lt;= 0.99 then  '0'
    when fc.[main_percent_score]  &gt; 1.0 and fc.[main_percent_score]  &lt;= 10.0 then  '10'
    when fc.[main_percent_score]  &gt; 10.0 and fc.[main_percent_score]  &lt;= 20.0 then  '20'
    when fc.[main_percent_score]  &gt;20.0 and fc.[main_percent_score]  &lt;= 30.0 then  '30'
    when fc.[main_percent_score]  &gt;30.0 and fc.[main_percent_score]  &lt;= 40.0 then  '40'
    when fc.[main_percent_score]  &gt;40.0 and fc.[main_percent_score]  &lt;= 50.0 then  '50'
    when fc.[main_percent_score]  &gt;50.0 and fc.[main_percent_score]  &lt;= 60.0 then  '60'
    when fc.[main_percent_score]  &gt;60.0 and fc.[main_percent_score]  &lt;= 70.0 then  '70'
    when fc.[main_percent_score]  &gt;70.0 and fc.[main_percent_score]  &lt;= 80.0 then  '80'
    when fc.[main_percent_score]  &gt;80.0 and fc.[main_percent_score]  &lt;= 90.0 then  '90'
    when fc.[main_percent_score]  &gt;90.0 and fc.[main_percent_score]  &lt;= 100.0 then  '100'
      end,
      place_id
  ORDER BY
      place_id
  </code></pre>
  
  <p>The output of this query is:</p>
  
  <pre><code>2   10  10
  2   20  20
  </code></pre>
  
  <p>I am expecting the result should be <code>b 30</code></p>