I'm trying to query my database in the following fashion:
Find the name, major and age of the youngest student who is either a Math major or is enrolled in a course taught by a professor that belongs to Computer Sciences.
The schema is as follows:
STUDENT(*snum: integer, sname: string, major: string, slevel: string, age: integer)
CLASS(*name: string, meets_at: date, room: string, fid: integer)
ENROLLED(*snum:integer, *cname: string )
FACULTY(*fid: integer, fname: string, deptid: integer)
DEPARTMENT (*deptid: integer,dname: string, Location:string)
(The fields with '*' are primary keys.)
I have the following query written, which correctly finds the student, but I can't figure out how to print the name and major.
SELECT MIN(s.age)
FROM student s
WHERE ( s.major = 'Math' )
OR s.snum IN (SELECT e.snum
FROM class c,
enrolled e,
faculty f,
department d
WHERE e.cname = c.NAME
AND c.fid = f.fid
AND d.dname = 'Computer Sciences');
I tried the following and got the error: "not a single-group group function"
SELECT s.sname,
s.major,
MIN(s.age)
FROM student s
WHERE ( s.major = 'Math' )
OR s.snum IN (SELECT e.snum
FROM class c,
enrolled e,
faculty f,
department d
WHERE e.cname = c.NAME
AND c.fid = f.fid
AND d.dname = 'Computer Sciences');
Any ideas? New to SQLPlus, so I'm still trying to learn how to build queries. Thank you in advance!