I have multiple product sales in different markets, and I need to sum up the totals for each title. To start:
mysql> 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 |
+--------+------------------------+-----------------+------------------+
This is what I currently am doing to get the GROUP BY title:
mysql> 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 |
+--------+-----------------+------------------+
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:
+--------+-----------------+------------------+
| title | us_earnings_usd | cad_earnings_cad |
+--------+-----------------+------------------+
| Gamers | 7.7500 | 4.0000 |
+--------+-----------------+------------------+
Try something like:
SUMis a function that will operate on each group when you have thatGROUP BYclause on your statement. For more similar functions, see MySQL aggregate functions.