oracle 10g sql with 子句编译错误

发布于 2024-09-29 04:26:08 字数 253 浏览 8 评论 0原文

编译错误显示“mm”和“cc”是无效标识符!

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转瞬即逝 2024-10-06 04:26:08

该错误是因为 mm 是子查询分解(AKA CTE)实例的名称,但正如您所看到的:

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

您尚未将 mm 声明为 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

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
人间不值得 2024-10-06 04:26:08

我猜你是想找一位授课次数最多的教练。

你能不能不使用

Select m.instructor FROM (select instructor, count(*) as c from class group by instructor order by 2 desc) m where rownum = 1

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文