gpt4 book ai didi

mysql - SQL (MySQL) - 如何在内连接中使用嵌套查询中指定的名称

转载 作者:行者123 更新时间:2023-11-29 06:36:43 26 4
gpt4 key购买 nike

SELECT name, age
FROM (SELECT name, age / 2
FROM maintable
INNER JOIN ......
) AS C
INNER JOIN (SELECT (Max(sales), person
FROM C) AS D ON .....

我正在尝试编写一个与上面类似的查询,但是当我在内连接部分引用 C 时,它说它不存在。我如何引用它?

最佳答案

您不能这样做,只能在子查询中使用子查询。

SELECT name, age
FROM
(
SELECT name, age / 2
FROM maintable
INNER JOIN ......
) AS C
INNER JOIN
(
SELECT Max(sales), person
FROM
(
SELECT name, age / 2
FROM maintable
INNER JOIN ......
) AS C
) AS D ON ....

如果你的mysql版本支持CTE

WITH C AS ( 
SELECT name, age / 2
FROM maintable
INNER JOIN ......
)
SELECT name, age
FROM C JOIN
(
SELECT Max(sales), person
FROM C
) AS D ON ....

关于mysql - SQL (MySQL) - 如何在内连接中使用嵌套查询中指定的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53507519/

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