Domanda

L'errore di compilazione dice "mm" e "cc" è identificativo valido!

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;
È stato utile?

Soluzione

L'errore è dovuto al fatto mm è il nome dell'istanza subquery Factoring (AKA CTE), ma come si può vedere:

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

Non hanno dichiarato mm come JOIN all'istanza m. Usa:

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

Altri suggerimenti

I presume che si sta cercando di ottenere l'istruttore con il maggior numero di classi.

Non potresti usare

Select m.instructor FROM (select instructor, count(*) as c from class group by instructor order by 2 desc) m where rownum = 1
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top