-2

我使用以下代码,但我试图理解别名,我收到此代码错误“SQL 命令未正确结束”,第 2 行

SELECT student.lastname, student.firstname
FROM student AS Student_Name
INNER JOIN memberof ON (Student_Name.SID = memberof.studentid)
INNER JOIN studentgroup ON (memberof.groupid = studentgroup.gid)
GROUP BY Student_Name.lastname , Student_Name.firstname 
HAVING COUNT(memberof.groupid) >= 2
4

2 回答 2

1

我认为您使用的 Oracle 显然不支持表别名的 as 关键字。

SELECT s.lastname, 
       s.firstname
FROM student s
INNER JOIN memberof 
    ON s.SID = memberof.studentid
INNER JOIN studentgroup 
    ON memberof.groupid = studentgroup.gid
GROUP BY s.lastname, 
         s.firstname 
HAVING COUNT(*) >= 2;
于 2013-04-24T00:17:40.653 回答
0

MYSQL:

如果您使用别名,则需要始终使用其别名来引用该表。通常我使用别名来缩短我的名字,这样我就不必输入太多了

SELECT s.lastname, s.firstname
FROM student AS s 
INNER JOIN memberof ON (s.SID = memberof.studentid)
INNER JOIN studentgroup ON (memberof.groupid = studentgroup.gid)
GROUP BY s.lastname , s.firstname 
HAVING COUNT(memberof.groupid) >= 2

"s" 可能太短取决于您的代码上下文,但您明白了

甲骨文

Oracle 不支持表别名的AS,仅支持列别名: SQL 命令未正确结束?

于 2013-04-24T00:08:40.137 回答