編譯錯誤說「mm」和「cc」是無效標識符!oracle 10g sql與子句編譯錯誤
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;
編譯錯誤說「mm」和「cc」是無效標識符!oracle 10g sql與子句編譯錯誤
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;
這個錯誤是因爲mm
是子查詢分解(AKA CTE)實例的名稱,但你可以看到:
SELECT m.instructor
FROM m
WHERE m.c = mm.cc;
您還沒有宣佈mm
爲連接到m
實例。使用:
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
你很棒,我不知道什麼是子查詢保理(aka cte)實例! – Rn2dy 2010-10-25 20:06:52
@baboonWorksFine:在Oracle中'WITH'語法被稱爲「子查詢因子分類」,在SQL Server中被稱爲「公用表表達式分解」(Common Query Table,簡稱AKA CTE)... – 2010-10-25 20:07:48
我認爲你正在試圖獲得大部分課程的指導。
你能不能用
Select m.instructor FROM (select instructor, count(*) as c from class group by instructor order by 2 desc) m where rownum = 1
你想怎麼處理關係 - 應該所有的關係顯示? – 2010-10-25 20:10:56