title: ORA-00979: not a GROUP BY expression while querying a View with a subquery
body: <p>I have a view as follows - It compiles just fine but when I try to select from it, I get a ORA-00979: not a GROUP BY expression error. If I eliminate the subquery (column 4) from the view, all works fine. Any ideas would be greatly appreciated! Thanks!! </p>
  
  <pre><code>select
      l.LAB_GROUP,
      l.NAME as LAB,
      b.NAME as BENCH,
      (select count(distinct s2.SAMPLE_NUMBER)
      from SAMPLE s2 inner join TEST t2 on s2.SAMPLE_NUMBER = t2.SAMPLE_NUMBER and t2.STATUS            in ('C', 'R') and s2.TEMPLATE &lt;&gt; 'QC_SAMPLE'
      inner join LABORATORY_ENTRY le2 on t2.ANALYSIS = le2.ANALYSIS
      where s2.LAB_GROUP = l.LAB_GROUP and le2.NAME = l.NAME and t2.X_BENCH = b.NAME and
      ((select count(t1.TEST_NUMBER)
      from TEST t1
      where t1.SAMPLE_NUMBER = t2.SAMPLE_NUMBER and t1.ANALYSIS = t2.ANALYSIS and t1.STATUS   &lt;&gt; 'R') = 0)) as RFR
  from LABORATORY l
  inner join LABORATORY_ENTRY le on le.NAME = l.NAME 
  inner join X_BENCH b on b.NAME = le.X_BENCH
  left join (SAMPLE s inner join TEST t on s.SAMPLE_NUMBER = t.SAMPLE_NUMBER and s.STATUS &lt;&gt; 'U'
  and s.TEMPLATE &lt;&gt; 'QC_SAMPLE' and t.STATUS in ('I', 'P')) on t.ANALYSIS = le.ANALYSIS and s.LAB_GROUP = l.LAB_GROUP
  left join V_LOC_DEPT_FAC ldf on ldf.LOCATION_NUMBER = s.STORAGE_LOC_NO 
  group by l.LAB_GROUP, l.NAME, b.NAME 
  </code></pre>