第一桌
CREATE TABLE qualified (
facultyid integer NOT NULL,
courseid character varying(16) NOT NULL,
datequalified character varying(16),
dq2 date,
CONSTRAINT qualified_pkey PRIMARY KEY (facultyid, courseid)
);
INSERT INTO qualified VALUES (3467, 'ISM 4212', to_date('9/1995', 'MM/YYYY'), date '1995-09-01');
INSERT INTO qualified VALUES (4756, 'ISM 3112', to_date('9/1991', 'MM/YYYY'), date '1991-09-01');
INSERT INTO qualified VALUES (2143, 'ISM 3113', to_date('9/1988', 'MM/YYYY'), date '1988-09-01');
INSERT INTO qualified VALUES (4756, 'ISM 3113', to_date('9/1991', 'MM/YYYY'), date '1991-09-01');
INSERT INTO qualified VALUES (2143, 'ISM 3112', to_date('9/1988', 'MM/YYYY'), date '1988-09-01');
INSERT INTO qualified VALUES (3467, 'ISM 4930', to_date('9/1996', 'MM/YYYY'), date '1996-09-01');
第二桌:
CREATE TABLE faculty (
facultyid integer NOT NULL,
facultyname character varying(25),
CONSTRAINT faculty_pkey PRIMARY KEY (facultyid)
);
INSERT INTO faculty VALUES (2143, 'Birkin');
INSERT INTO faculty VALUES (3467, 'Berndt');
INSERT INTO faculty VALUES (4756, 'Collins');
质询:是否有教师有资格教授ISM 4212并且没有资格教授ISM 4930?
我试过的查询:
SELECT q.facultyid, facultyname, q.courseid
FROM qualified q, faculty fa
WHERE q.facultyid = fa.facultyid AND courseid = 'ISM 4212'
MINUS
SELECT q.facultyid, facultyname, q.courseid
FROM qualified q, faculty fa
WHERE q.facultyid = fa.facultyid AND courseid = 'ISM 4930';
显示:3467 Berndt ISM 4212
而不是:NOTHING / No Result。
答案 0 :(得分:0)
从select子句中删除以下内容解决了问题:
q.courseid