1
晚上好! 我有問題,因爲我不能在WHERE和 ORDER BY中使用MAXGROWTHPARENT值。 我寫了這條查詢:POSTGRESQL:在WHERE子句中使用之前的計算值
SELECT PERSON.*,
(
SELECT MAX(PARENT.GROWTH)
FROM MAN PARENT
WHERE
(PARENT.ID = PERSON.ID_FATHER)
OR
(PARENT.ID = PERSON.ID_MOTHER)
) AS MAXGROWTHPARENT
FROM MAN PERSON
WHERE PERSON.GROWTH >
(
SELECT MAX(PARENT.GROWTH)
FROM MAN PARENT
WHERE
(PARENT.ID = PERSON.ID_FATHER)
OR
(PARENT.ID = PERSON.ID_MOTHER)
)
ORDER BY (PERSON.GROWTH -
(
SELECT MAX(PARENT.GROWTH)
FROM MAN PARENT
WHERE
(PARENT.ID = PERSON.ID_FATHER)
OR
(PARENT.ID = PERSON.ID_MOTHER)
)
);
我的代碼看起來非常難看。你能告訴我如何在WHERE和ORDER BY子句中使用MAXGROWTHPARENT ?