【问题标题】:Error Code: 1146. Table 'fe539.t' doesn't exist错误代码:1146。表 'fe539.t' 不存在
【发布时间】:2017-10-01 09:59:43
【问题描述】:

我在 MySQL 中遇到以下问题

问题出现在别名“T”

select course_id, sec_id, enrollment 
from (
    select course_id, sec_id, count(ID) as enrollment
    from section natural join takes
    where semester = 'Fall' and year =2009
    group by course_id, sec_id
) as T
where enrollment = (select max(enrollment) from T);

【问题讨论】:

  • 自然连接令人讨厌 - 使用显式连接更容易理解(对于阅读器和优化器)。
  • 你应该阅读mysql的执行顺序。在执行顺序中选择出现在 where 之后这一事实与此相关。

标签: mysql


【解决方案1】:

如果你没有任何平局,我认为你可能会逃脱类似以下的事情。

select course_id, sec_id, count(*) as enrollment
        from section s
        join takes t on s.sec_id = t.course_id
        where semester = 'Fall' and year =2009
        group by course_id, sec_id 
        order by count(*) desc 
        limit 1 
;

【讨论】:

    猜你喜欢
    • 2013-03-29
    • 2013-10-20
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2015-06-01
    • 1970-01-01
    相关资源
    最近更新 更多