gpt4 book ai didi

mysql - 在第三级子查询中使用列

转载 作者:行者123 更新时间:2023-11-29 14:12:51 25 4
gpt4 key购买 nike

如何在第三级子查询中使用顶级 SELECT 中的列?

我尝试了这个,但它给出了:未知列 foo.id

SELECT foo.id,
(
SELECT SUM(bar.amount)
FROM bar
JOIN (
SELECT DISTINCT ding.id
FROM baz
JOIN ding ON ding.baz_id = baz.id
WHERE baz.foo_id = foo.id
) AS j ON j.id = bar.id
) AS amount
FROM foo

最佳答案

尝试一下 选择 foo_id

FROM (
SELECT SUM(bar.amount),j.foo_id
FROM bar
JOIN (
SELECT DISTINCT ding.id,baz.foo_id
FROM baz
JOIN ding ON ding.baz_id = baz.id
) AS j ON j.id = bar.id
) AS amount;

关于mysql - 在第三级子查询中使用列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13186402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com