title: Sum sales from different tables
body: <p>I have 5 tables related to sales. Three of them are like this:
  <a href="https://i.stack.imgur.com/SoaoU.png" rel="nofollow noreferrer">Product_table_image</a></p>
  <p>They are called product_a, product_b, product_c
  The other tables are the time_id table which contains the reference for the date_id and the customers' table, which contains the details of customers.</p>
  <p><a href="https://i.stack.imgur.com/FT7bb.png" rel="nofollow noreferrer">time_id table</a></p>
  <p>and</p>
  <p><a href="https://i.stack.imgur.com/HSm1S.png" rel="nofollow noreferrer">customer_table</a></p>
  <p>The 3 tables refer to the sales of different products, but the products are not important in this context, because what I need is to sum up all the values per month per customer. There are cases when one or more customers might not have made a purchase of a certain product,  which means not all customers ids will be in all products tables and that's what I can't figure out how to solve. It seems that my code is only able to fetch and sum when the clients have made purchases in all  3 tables.</p>
  <p>So this is what I was able to come up with:</p>
  <pre><code>SELECT C.customer_id, ROUND((A.pa + B.pa + C.pc)* 1, 2) AS total,C.month_id 
  FROM (SELECT customer.customer_id, SUM(product_a.amount) AS pa , time_id.month_id FROM customer
  INNER JOIN product_a  on customer.customer_id = product_a.customer_id
  INNER JOIN time_id on  product_a.date_id = time_id.date_id
  
   GROUP BY customer.customer_id, time_id.month_id) AS A
  
  CROSS JOIN
  
  (SELECT customer.customer_id, SUM(product_a.amount) AS pb , time_id.month_id FROM customer
   INNER JOIN product_b  on customer.customer_id = product_b.customer_id
   INNER JOIN time_id on  product_b.date_id = time_id.date_id
   
   GROUP BY customer.customer_id, time_id.month_id) AS B
  
  CROSS JOIN
  
  (SELECT customer.customer_id, SUM(product_a.amount) AS pc , time_id.month_id FROM customer
   INNER JOIN product_c  on customer.customer_id = product_c.customer_id
   INNER JOIN time_id on  product_c.date_id = time_id.date_id
   
   GROUP BY customer.customer_id, time_id.month_id) AS C
  
  GROUP BY C.month_id, C.customer_id
  ORDER BY C.month_id;
  </code></pre>
  <p>I've been stuck in it for a while, so any help is appreciated!</p>