Question

The compilation error says "mm" and "cc" is invalid identifier!

with m as (
  select instructor, 
         count(*) as c 
    from class 
group by instructor),
     mm as ( 
  select max(m.c) as cc 
    from m)
select m.instructor 
  from m 
 where m.c = mm.cc;
Was it helpful?

Solution

The error is because mm is the name of the Subquery Factoring (AKA CTE) instance, but as you can see:

SELECT m.instructor 
 FROM m 
WHERE m.c = mm.cc;

You haven't declared mm as a JOIN to the m instance. Use:

WITH m AS (
    SELECT instructor, 
           COUNT(*) as c 
      FROM CLASS
  GROUP BY instructor),
     mm AS ( 
    SELECT MAX(m.c) as cc 
      FROM m)
SELECT m.instructor 
  FROM m
  JOIN mm ON mm.cc = m.c

OTHER TIPS

I presume you are trying to get the instructer with the most classes.

Could you not use

Select m.instructor FROM (select instructor, count(*) as c from class group by instructor order by 2 desc) m where rownum = 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top