在我从带有 COALESCE 的 SELECT 中获得结果后,我试图加入一个表
SELECT
COALESCE(
(
SELECT
relocations.location_id
FROM
relocations
WHERE
parts.id=relocation.part_id
ORDER BY
relocations.date_moved
DESC
LIMIT
1
)
,
parts.location_id
) AS locationId,
locations.name
FROM
parts
JOIN
locations ON locations.id=locationId
但是查询无效,MySQL 告诉我 locationId 是一个未知列。我该如何解决这个问题?
表结构
[零件] id | location_id
[搬迁] id | location_id | 日期移动
[地点] id | 姓名