title: Multiple Aggregate with different Group By
body: <p>I have table User, Company, ParentCompany and table Goal.
  Each Company have ParentCompany, and each User inside one Company. Goal have number of action, and type of Goal, user who execute the goal, and time executed.</p>
  
  <p>I want to calculate the number of action in a date range for each type of Goal, for each user, company, and parent_company. Number of action for each company equal to sum of action for user that reside in that company.</p>
  
  <p>More or less after some join query, I able to get this table below, where column id is id of company, parent_id is id of companyparent, and num is number of goal for all user inside of id company.</p>
  
  <pre><code>id          parent_id            num
  ----------- -------------------- -----------------------
  1           3                    1
  2           1                    2
  3           1                    1
  4           2                    4
  </code></pre>
  
  <p>Now I want to make it like below:</p>
  
  <pre><code>id          parent_id            sum_id         sum_parent
  ----------- -------------------- -------------- -------------
  1           3                    1              1
  2           1                    2              3
  3           1                    1              3
  4           2                    4              4
  </code></pre>
  
  <p>How can I make it works? I can get one of the value (sum_id or sum_parent) with GROUP BY,</p>
  
  <pre><code>SELECT id,SUM(num) AS sum_id FROM tableA GROUP BY id
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT parent_id,SUM(num) AS sum_parent FROM tableA GROUP BY parent_id
  </code></pre>
  
  <p>but is there any way to make it only in one query? <code>tableA</code> results from query with 5 join inside.</p>