我正在尝试使用 postgresql 进行查询。该数据库包含两个关系:“kingdom”,其中包括一些英国国王,以及“dinasty”,其中包含一些来自 stuart dinasty 的人
关系“王国”包括国王的名字以及他的王国开始和结束的时间。关系“神圣”包括姓名、性别、出生和死亡。
我想问的是他死时最年长的国王。
通过我的查询,我在第 3 行(不在)收到此错误:subquery has too many columns
这是查询:
SELECT kingdom.king, dinasty.birth, dinasty.death
FROM kingdom, dinasty
WHERE kingdom.king = dinasty.name AND kingdom.king NOT IN
(
SELECT DISTINCT R1.king, R1.birth, R1.death
FROM
(
SELECT DISTINCT R1.king, D1.birth, D1.death
FROM kingdom AS R1, dinasty AS D1, dinasty AS D2
WHERE R1.king=D1.name
) AS R1,
(
SELECT DISTINCT R1.king, D1.birth, D1.death
FROM kingdom AS R1, dinasty AS D1, dinasty AS D2
WHERE R1.king=D1.name
) AS R2
WHERE R1.death-R1.birth < R2.death-R2.birth
);
NOT IN 里面的内容是正确的。