title: How could I get the sub sum of a value?
body: <p>I have the following [relation.]<br/><img src="https://i.stack.imgur.com/W4N8w.png" alt="1" /></p>
  <p>With some of the following data:</p>
  <pre><code>dates
  +---------+------------+------+-------+------+
  | dateKey | date       | day  | month | year |
  +---------+------------+------+-------+------+
  |       1 | 01/01/2020 |    1 |     1 | 2000 |
  |       2 | 02/01/2020 |    2 |     1 | 2000 |
  |     ... |        ... |  ... |   ... |  ... |
  +---------+------------+------+-------+------+
  
  sales
  +------------+------------+----------+------+
  | dateKey    | companyKey | produced | sold |
  +------------+------------+----------+------+
  |          1 | 1          |        0 |    0 |
  |          1 | 2          |        0 |    0 |
  |          1 | 3          |       12 |    2 |
  |          1 | 4          |      123 |   12 |
  |     ...    | ...        |      ... |  ... |
  |        365 | 12         |     1234 |  123 |
  +------------+------------+----------+------+
  
  company
  |------------+----------------+-------------------------+----------------+
  | companyKey | companyAcronym |        companyName      | employeeNumber |
  +------------+----------------+-------------------------+----------------+
  |          1 |         AAL    | Anit and Alson Limited  |            251 |
  |          2 |         ABB    | Abban                   |             26 |
  |          3 |         AND    | Andelson                |             57 |
  |          4 |         APL    | Aperal                  |            137 |
  |          5 |         BAN    | Bansil                  |             72 |
  |        ... |         ...    | ...                     |            ... |
  |------------+----------------+-------------------------+----------------+
  </code></pre>
  <p>I am trying to get the total number of goods sold per month by each company. What I have tried so far is this:</p>
  <pre><code>SELECT month, companyName, SUM(sales) AS totalSales
  FROM sales AS s 
  JOIN company AS c ON s.companyKey = c.companyKey
  JOIN dates AS d ON s.dateKey = d.dateKey
  GROUP BY companyName , month;
  </code></pre>
  <p>This doesn't work, as I still get a row for each day of the month.</p>