The compilation error says "mm" and "cc" is invalid identifier!
with m as (
select instr开发者_StackOverflow社区uctor,
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;
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
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
精彩评论