我试过这个问题:医院的名称是什么,所有医生都在这个国家工作。但结果不是我所期望的,并且它有语法错误。
我有这些表格:
CREATE TABLE Hospital (
hid INT PRIMARY KEY,
name VARCHAR(127) UNIQUE,
country VARCHAR(127),
area INT
);
CREATE TABLE Doctor (
ic INT PRIMARY KEY,
name VARCHAR(127),
date_of_birth INT,
);
CREATE TABLE Work (
hid INT,
ic INT,
since INT,
FOREIGN KEY (hid) REFERENCES Hospital (hid),
FOREIGN KEY (ic) REFERENCES Doctor (ic),
PRIMARY KEY (hid,ic)
);
我试过这个:
SELECT DISTINCT H.name
FROM Hospital H, Doctor D, Work W
WHERE H.hid = W.hid
AND D.ic = W.ic
AND NOT EXISTS (SELECT DISTINCT H2.name
FROM Hospital H2
WHERE H2.country = H.country AND W.hid = H2.hid AND D.ic != W.ic)
我在想的是在同一个国家找医院H2,但医生D不能工作。
感谢。