繁体   English   中英

关键字“ where”附近的SQL错误语法

[英]SQL Incorrect syntax near the keyword 'where'

这是我的代码,由于某种原因,我不断收到表示以下内容的错误

关键字“ where”附近的语法不正确

我想知道我在做什么错。

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

最好避免natural join 因为它使用公共字段名-而不是显式定义的外键关系-实际上它只是一个等待发生的错误。

如果您的数据库不支持natural join则会出现此问题。 在这种情况下, naturalsection的表别名。 这只是一个猜测。

我建议您将查询写为:

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

您需要为on子句填写适当的列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM