title: Sub-Select on MySQL
body: <p>I don't know if this is possible but I'm trying to make a select queries with a couple of JOINS with a WHERE statement. What I need is a field based on a particular WHERE and another field with different WHERE.</p>
  
  <p>Current SQL query:</p>
  
  <pre><code>SELECT SUM(a.totaltime), b.user_name, MONTHNAME(a.date)
  FROM a 
  JOIN c on c.id = a.id                                                                    
  JOIN b on b.userid = c.userid    
  LEFT JOIN d on a.projid = d.projectid                                                                       
  LEFT JOIN e on a.account_id = e.salesorderid                                                          
  LEFT JOIN f on e.salesorderid = f.salesorderid                                                      
  LEFT JOIN g on d.projectid = g.projectid                                                                     
  WHERE c.deleted != "1" AND YEAR(DATE(NOW())) AND ( f.cf_991 = '1' OR g.cf_990 = '1') 
  group by user_name,MONTHNAME(a.date);
  </code></pre>
  
  <p>This works fine but I need to include another field this time WHERE would be:</p>
  
  <pre><code>WHERE c.deleted != "1" AND YEAR(DATE(NOW())) AND ( f.cf_991 = '0' OR g.cf_990 = '0') 
  </code></pre>
  
  <p>Any help is greatly appreciated thanks</p>
  
  <p>EDIT:</p>
  
  <p>CURRENT OUTPUT IS:</p>
  
  <pre><code> total_time        username        MONTHNAME(a.date)
   22.5              admin           April
   21                admin           June
   15                max             April
  </code></pre>
  
  <p>So the above is based on f.cf_991 = '1' OR g.cf_990 = '1'</p>
  
  <p>What I need is this:</p>
  
  <pre><code> total_time        username        MONTHNAME(a.date)        total_time_2  
   22.5              admin           April                    5
   21                admin           June                     9
   15                max             April                    13
  </code></pre>
  
  <p>total_time_2 is based on f.cf_991 = '0' OR g.cf_990 = '0'.</p>