title: Is there a way to get a query return the users that the count of a certain condition is above a certain number?
body: <p>I am having trouble trying to figure the correct way to write an SQL query. Ok so let's say that we have three tables MyUser, Consult, Measurement. I would like to have a query that returns to me the users that have created more than 30 measurements in the past thirty days but haven't received a consult in the past 30 days. So far i have got something like this:</p>
  <pre><code>FROM MyUser a
  where a.isActive = 1 AND a.email = 'test@gmail' AND a.userRole = 'patient'
  having 30 &lt; (select COUNT(*) From Measurement m, Consults c
          WHERE c.patient_email = 'test@gmail'
           AND m.patient_email = 'test@gmail'
           AND m.measurement_created_date BETWEEN '2020-07-20' AND '2020-10-20'
           AND NOT c.consult_created_date BETWEEN '2020-10-20'AND '2020-11-20')
  </code></pre>
  <p>This doesn't work properly.
  Another aproach is:</p>
  <pre><code>SELECT COUNT (*) FROM Measurement m, MyUser a, Consults c
  WHERE a.isActive = 1 AND a.email = 'test@gmail.com' AND a.userRole = 'patient'
  AND c.patient_email = 'test@gmail'
  AND m.patient_email = a.email
  AND m.measurement_created_date BETWEEN '2020-08-10'AND '2020-09-10'
  AND NOT c.consult_created_date BETWEEN '2020-08-10'AND '2020-19-10'
  
  </code></pre>
  <p>or something like that but this doesn't return the users and only returns the count. Can someone provide some guidance or solution to this? Thanks</p>