title: How to count with cases without subqueries in this situation
body: <p>I have a table grades[Student, Grade]
  My task is to сount the amount of students, have 2 A's (2) and at least one D (2).
  <strong>The most painful part is that i shouldn't use sql subqueries</strong></p>
  <p>That abomination i come up with would only list such nulls and students which fit by condition
  Any ideas how to count them ? Or rework query?</p>
  <pre><code>SELECT CASE WHEN 
              (
                sum(CASE WHEN g1.grade = 5 
                       THEN 1
                       ELSE 0 
                       END) &gt; 2
                
              )
              AND
              (
                sum(CASE WHEN g1.grade = 2 
                       THEN 1
                       ELSE 0 
                       END) &gt; 0              
              )
              THEN g1.student_name
              ELSE NULL
              END as student_name
              
  FROM grades g1
  group by g1.student_name
  </code></pre>