0
我試圖做這個查詢:西班牙醫院的名稱是什麼,在那裏工作超過2醫生,只爲該醫院工作。但結果並非我所期望的。SQL DML甲骨文查詢
我有這些表:
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 Doctor D, Work W, Hospital H
WHERE D.bi = W.bi AND H.country = 'Spain' AND H.hid = W.hid AND W.ic = D.ic
AND NOT EXISTS(
SELECT *
FROM Hospital H2
WHERE H2.hid = W.hid
)
GROUP BY (H.name)
HAVING COUNT(D.ic) > 2
;
感謝。
感謝您的幫助和解釋。 – tomss