select a.customer_id from
(
select customer_id, username, referral_id from customer
) a,
(
select username as new from customer where referral_id = a.customer_id
) b
我的表架构具有元数据,因此尝试在另一个查询中获取并使用它,但在 where 子句中出现错误未知列 a.customer_id 。如何以正确的方式编写上述查询
最佳答案
您编写了一个有趣的查询。我想这就是你想要的:
select c.customer_id
from customer c join
customer cr
on c.customer_id = cr.referral_id;
您的查询显示了一些 SQL 知识,但您似乎并不理解最基本和关键的概念之一:连接。无论如何,您不需要为此使用子查询。您希望将连接条件放入 on
子句中。并且您想使用显式连接语法。你应该研究一下连接。
关于mysql 表单元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408439/