title: SQL statement using case, like, and having
body: <p>I am using an Oracle based system. </p>
  
  <p>How do you use like, having, and a case statement together?</p>
  
  <p>I am basically trying to list all of the unique individuals that are found in a transactional table that have more than 4 "Class A" transactions, or more than 1 "Class B" transactions. The reason why I want to use <code>like</code> is because the only way to diferentiate between transaction classes is by using a <code>like</code> statement in the transaction type column.</p>
  
  <p>For example, there are many transaction types, but only "Class A" have <code>'%ABC%'</code> as part of their transaction type, and "Class B" are all the other types that do not have <code>'%ABC%'</code> in their transaction type column.</p>
  
  <p>So again, I want my query to return only the indiv ids that have more than 4 "Class A" Transactions, or 1 "Class B" transaction.</p>
  
  <p>here is what I have so far:</p>
  
  <pre><code>select tt.indiv_id, count(*) from transactiontable tt
  group by tt.indiv_id
  case when tt.tran_type like '%ABC'
  having count(*) &gt; 4
  else
  having count(*)&gt;1.
  </code></pre>
  
  <p>I have searched a good bit on the site and I have not found an example using all of these functions together.</p>