I'm trying to run a query on a database that has 3 tables: COURSE, SECTION, ENROLL.
They are creating as such:
create table COURSE
(
Cno varchar(9) primary key,
Cname varchar(50),
Credit int check (Credit > 0)
);
create table SECTION
(
Cno varchar(9) REFERENCES COURSE(cno),
Sno varchar(9),
Semester varchar(15) check(Semester in('Fall','Spring','Summer')),
Year int,
Sid varchar(9) primary key
);
create table ENROLL
(
Mno varchar(9) REFERENCES STUDENT(Mno),
Sid varchar(9) REFERENCES SECTION(Sid),
Grade CHAR check(Grade in('A','B','C','D','F')),
primary key(Mno,Sid)
);
I'm trying to run a SUM on all the credits for classes that a student is enrolled in. This is how I'm trying to accomplish this:
select
SUM(select Credit
from COURSE c
where c.Cno = (select s.Cno
from SECTION s
where s.Sid = (select Sid
from ENROLL
where Mno = @mNum));
However I'm getting an error in Visual Studio that says
Incorrect syntax near 'select' (the second select statement)
What is it that is wrong? Any help would be greatly appreciated.