title: SQL query to get group by and distinct values at the same time
body: <p>I'm having trouble trying to define the SQL query for this table: </p>
  
  <p>There's a table of patients and their weight readings recorded on visits with the following columns:</p>
  
  <ul>
  <li>patient ID</li>
  <li>weight reading</li>
  <li>visit ID (one per visit)</li>
  </ul>
  
  <p>In other words, if in two records two  visit IDs are the same, then two weight readings have been taken on that same visit date. </p>
  
  <p>I have this query to "get all patients with at least two weight readings above 150":</p>
  
  <pre><code>select patient_id 
    from patients 
   where weight_val &gt; 50 
  group by patient_id 
    having count(*) &gt;= 2
  </code></pre>
  
  <p>Here's my problem: What if I want to modify this query so that I can query the following:</p>
  
  <ol>
  <li>"get all patients with at least two weight readings above 150 on different visits" </li>
  <li>"get all patients with at least two weight readings above 150 on the same visit"</li>
  </ol>
  
  <p>Is it possible to do it without removing the "group by" statement? if not, what is your recommended approach? I'm also open to adding a date column instead of visit ID if it makes it easier (i'm using Oracle).</p>