sql server2008代码问题

 select course_id, sec_id, count(ID)

    from section natural join takes

    where semester = 'Fall' and year = 2009

    group by course_id, sec_id

求大佬帮忙改一下,让他能在Sql server2008上运行

mssqlserver不支持natural join,改成inner join或者join。

select section.course_id, section.sec_id, count(section.ID)--防止重名最好加上表名称,要不2个表中字段一样会出错

from section 

inner join takes on section.sec_id=takes.sec_id--自己注意改下这里,2个表中通过哪个字段关联的,我这里只是猜测的

where semester = 'Fall' and year = 2009

group by course_id, sec_id

对你有帮助能点击个采纳吗,谢谢~

select course_id, sec_id, count(ID)

    from section natural join takes

    where semester = 'Fall' and year = 2009

    group by course_id, sec_id

where 前面应该还有一个on语句,二个表互相关联的字段。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632