title: (SQL) How to average values with the same IDs
body: <p>I have sql code like this:</p>
  
  <pre><code>SELECT ID_song as ID, rate
  FROM Songs
      JOIN Rating USING (ID_song)
  order by ID_song;
  </code></pre>
  
  <p>Output is:</p>
  
  <pre class="lang-none prettyprint-override"><code>  ID ¦ rate  
   ----+------ 
    27 ¦ 10    
    28 ¦ 1     
    31 ¦ 4     
    31 ¦ 1     
    41 ¦ 7     
    41 ¦ 3     
    44 ¦ 1     
    44 ¦ 7     
  </code></pre>
  
  <p>I want to average rate for duplicate IDs to have always one unique ID with its average value of rate like this:</p>
  
  <p>Output is:</p>
  
  <pre class="lang-none prettyprint-override"><code>  ID ¦ rate  
   ----+------ 
    27 ¦ 10    
    28 ¦ 1     
    31 ¦ 2.5   
    41 ¦ 5     
    44 ¦ 4       
  </code></pre>