title: SQL query with having function to only includes parts of another column?
body: <p>I am trying to find fact_order_id's that have <strong>beverage only items</strong>. This would make the fact_order_id not include any food items.</p>
  <pre><code>fact_order_id
  fact_order_line_id
  category Group
  category Name
  </code></pre>
  <p>I have used 2 separate SQL Queries below. When I go back and check my work, I notice some fact_order_id's in the output <strong>aren't</strong> beverage only orders. Here are the 2 separate SQL Queries that give me the same output:</p>
  <pre><code>select fact_order_id
  from my_table
  group by fact_order_id
  having avg((category_group like 'Beverage%')::int) = 1;
  
  
  select fact_order_id
  from my_table
  group by fact_order_id
  having avg(CASE WHEN category_group like 'Beverage%' THEN 1 ELSE 0 END)=1;
  </code></pre>
  <p>Both of the outputs above give me the same number of rows. Whenever I cross check the fact_order_id, some of them would include an output with food items.</p>
  <p>This fact_order_id shouldn't be included in my output since there are other non-beverage items on the order. There are 2 Category Group that have a beverage name (<strong>Beverage (non-alcohol) &amp; Beverage (specialty)</strong>). Is there a better way of creating a SQL Query to only have an output of fact_order_id's that are beverage only orders?</p>
  <p><strong>I am using PostgreSQL Version: 08.00.0002</strong></p>