title: SQL group function nested too deeply
body: <p>I'm trying to create an sql query that will return the smallest occurrence of an id appearing between two tables however I keep getting the error with the line <code>HAVING MIN(COUNT(E.C_SE_ID))</code>. Oracle is saying that the group by function is nested too deeply.
  I cannot think of another way of returning  <code>C_SE_ID</code></p>
  
  <pre><code>SELECT CS.C_SE_ID, MIN(COUNT(E.C_SE_ID))
  FROM COURSE_SECTION CS, ENROLLMENT E, LOCATION L
  WHERE CS.C_SE_ID=E.C_SE_ID
  AND CS.LOC_ID=L.LOC_ID
  AND L.BLDG_CODE='DBW'
  GROUP BY CS.C_SE_ID
  HAVING MIN(COUNT(E.C_SE_ID));
  </code></pre>
  
  <p>in enrollment table <code>s_id</code> and <code>c_se_id</code> are linked, I'm trying to get all the <code>s_id</code> that are related to that <code>c_se_id</code>. with the updated query oracle doesn't like the <code>select *</code> (for obvious reasons) but when I change it too <code>e.c_Se_id</code> I get nothing.     </p>
  
  <pre><code>SELECT E.S_ID
  FROM COURSE_SECTION CS, ENROLLMENT E
  WHERE CS.C_SE_ID=E.C_SE_ID
  AND E.C_SE_ID =(
  select *
  from (select CS.C_SE_ID, count(*) as cnt,
        max(count(*)) over (partition by cs.c_se_id) as maxcnt
        from COURSE_SECTION CS join
             ENROLLMENT E
             on CS.C_SE_ID=E.C_SE_ID join
             LOCATION L
             on CS.LOC_ID=L.LOC_ID
        where L.BLDG_CODE='DBW'
        GROUP BY CS.C_SE_ID
        order by count(*) desc
       ) t
  where cnt = maxcnt);
  </code></pre>