title: Group Using SQL and Keeping Initial Records
body: <p>I am using GROUP BY and HAVING to select a number of consumers that qualify for a program in our company. We're basing this on the balance that consumer has from any number of accounts that they are associated with (One To Many). </p>
  
  <p>Here is an example of the code: </p>
  
  <pre><code>select   consumerid, 
           sum(balanceonaccts) bal,
           group_concat(accountid) accts
  from     accounts
  join     consumer 
  on       consumer.consumerid = accounts.consumerid 
  group by consumerid
  having   bal &gt; 300"
  </code></pre>
  
  <p>This gives me information on who meets the qualifications on the consumer level, however, the only way I've been able to identify the accounts that combined to meet the balance is to use group_concat(). </p>
  
  <p>I was wondering if there was a method to identify those consumers who's accounts combined meet the balance criteria, and then somehow move the output down to the account level.</p>
  
  <p>When I attempt to:</p>
  
  <pre><code>group by accountid
  </code></pre>
  
  <p>It excludes consumers who's accounts alone wouldn't meet the balance required but summed together would pass the threshold.</p>