title: SQL aggregate function subquery
body: <p>What I want to do is count the number of rows returned by a subquery, essentially the following:</p>
  
  <pre><code>select pp.prop_id, COUNT((select employee_id from employee e where e.ao1_hours &gt; 0))
    from proposal_piece pp
  
    group by pp.prop_id
    order by pp.prop_id
  </code></pre>
  
  <p>Here is my error message:</p>
  
  <pre><code>Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
  </code></pre>
  
  <p>Why does this not work? If select is just returning a bunch of <code>employee_id's</code> with a filtering criteria why can't I count the number of rows or <code>employee_id's</code> that are being returned?</p>
  
  <p>I am looking to count the number of distinct employees that have <code>ao1_hours &gt; 0</code>. Grouped by the <code>prop</code>.</p>
  
  <p>Here is some structural information about my database, as part of a query.</p>
  
  <pre><code>    from proposal_piece pp
      INNER JOIN employee e
      on pp.employee_id = e.employee_id
  </code></pre>
  
  <p>Thanks!</p>