Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a GROUP BY statement to sum rows
    text
    copied!<p>I have multiple product sales in different markets, and I need to sum up the totals for each title. To start:</p> <pre><code>mysql&gt; SELECT title, partner_share_currency, us_earnings_usd, cad_earnings_cad FROM raw_financials WHERE title LIKE "%Gamers%"; +--------+------------------------+-----------------+------------------+ | title | partner_share_currency | us_earnings_usd | cad_earnings_cad | +--------+------------------------+-----------------+------------------+ | Gamers | USD | 3.2500 | 0.0000 | | Gamers | CAD | 0.0000 | 4.0000 | | Gamers | USD | 4.5000 | 0.0000 | +--------+------------------------+-----------------+------------------+ </code></pre> <p>This is what I currently am doing to get the GROUP BY title:</p> <pre><code>mysql&gt; SELECT title, us_earnings_usd, cad_earnings_cad FROM raw_financials WHERE title LIKE "%Gamers%" GROUP BY title; +--------+-----------------+------------------+ | title | us_earnings_usd | cad_earnings_cad | +--------+-----------------+------------------+ | Gamers | 3.2500 | 0.0000 | +--------+-----------------+------------------+ </code></pre> <p>As you can see, it does not sum the value rows. How would I change the SELECT statement such that it sums up the value rows, to give me:</p> <pre><code>+--------+-----------------+------------------+ | title | us_earnings_usd | cad_earnings_cad | +--------+-----------------+------------------+ | Gamers | 7.7500 | 4.0000 | +--------+-----------------+------------------+ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload