title: MySQL : Insert into... Select from .... On Duplicate Key
body: <p>I have a record from <strong>table A</strong> say :</p>
  
  <pre><code>_____________________________________________________________________________
      Date       |      country        |      channel      |       clicks  
  _____________________________________________________________________________
      1-01-2016  |         US          |        MTV        |        100
  
      1-01-2016  |         US          |        MTV        |         50
  _____________________________________________________________________________
  </code></pre>
  
  <p>I insert this record into another <strong>table B</strong> Using the query :</p>
  
  <pre><code>INSERT INTO B 
  SELECT 
    DATE,
    country,
    channel,
    SUM(clicks) AS clicks 
  FROM
    A 
  GROUP BY DATE,
    country,
    channel;
  </code></pre>
  
  <p>Now <strong>Table B</strong> looks like :</p>
  
  <pre><code>_____________________________________________________________________________
      Date       |      country        |      channel      |       clicks  
  _____________________________________________________________________________
      1-01-2016  |         US          |        MTV        |        150
  _____________________________________________________________________________
  </code></pre>
  
  <p>At some other instant in time I get another record in <strong>table A</strong> say</p>
  
  <pre><code>_____________________________________________________________________________
          Date       |      country        |      channel      |       clicks  
  _____________________________________________________________________________
          1-01-2016  |         US          |        MTV        |        300
  _____________________________________________________________________________
  </code></pre>
  
  <p>Now I want to <strong>update</strong> the old record in <strong>table B</strong> which should look like this :</p>
  
  <pre><code>_____________________________________________________________________________
          Date       |      country        |      channel      |       clicks  
  _______________________________________________________________________________
          1-01-2016  |         US          |        MTV        |        450
  _____________________________________________________________________________
  </code></pre>
  
  <p>How can I do this with <strong>MySQL</strong></p>