gpt4 book ai didi

mysql - 与 INNER JOIN 作斗争

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

我有 2 个数据表,一个名为 Actor ,一个名为客户。我想要实现的是获取具有相同姓氏的客户和 Actor 的列表。姓名将按姓氏排序。

我遇到的问题是我的 WHERE 行似乎返回空白结果

-- the NOW()'Jordan_Rasmussen' is simply there so that instructors will see that its me when I screenshot the results, as their instructions state.

SELECT NOW()'Jordan_Rasmussen',
CONCAT(c.first_name, ' ', c.last_name) AS customer_name,
CONCAT(a.first_name, ' ', a.last_name) AS actor_name
FROM customer AS c
INNER JOIN actor AS a ON c.customer_id = a.actor_id
WHERE c.last_name LIKE a.last_name
ORDER BY c.last_name;

最佳答案

您必须加入姓氏,而不是 ID:

SELECT NOW() AS `Jordan_Rasmussen`,
CONCAT(c.first_name, ' ', c.last_name) AS customer_name,
CONCAT(a.first_name, ' ', a.last_name) AS actor_name
FROM customer AS c INNER JOIN actor AS a
ON c.last_name = a.last_name
ORDER BY c.last_name;

关于mysql - 与 INNER JOIN 作斗争,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59120377/

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