错误1

column "student.sno" must appear in the GROUP BY clause or be used in an aggregate function

group by是按照某一个属性来分类,如果此时student.sno不在其中,分完类后,就无法找到这个属性。除非使用聚集函数,这个时候只需要计算值,并不需要找到这个属性。

错误2

正确写法:

select sname from student s1 where not exists (select cno from course where s1.sdept = course.sdept except select cno from sc where s1.sno = sc.sno);

错误写法(删去了一对括号):

select sname from student s1 where not exists select cno from course where s1.sdept = course.sdept except select cno from sc where s1.sno = sc.sno;

-- ERROR:  syntax error at or near "select"
-- 第1行select sname from student s1 where not exists select cno fro...

解释:可能是会有歧义,不知道not exists判断的是哪个。

注意

未完。。。

更多推荐