我试过这个查询:在这个国家工作的所有医生都工作的医院的名称是什么。但结果不是我所期望的,并且有语法错误。
我有这些表:
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 不工作。
谢谢。