gpt4 book ai didi

mysql - MySQL 查询格式错误

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

这是查询。

SELECT pl.id, pl.latitude, pl.longitude, pl.userId, pl.time, pl.type, com.id as com_id, com.text, com.time as com_time,
(SELECT name as com_name, email as com_email, picture as com_picture
FROM aa_users
LEFT JOIN aa_comments ON aa_users.id = aa_comments.user_id)
usr.name as com_usr_name,
usr.email as com_usr_email,
usr.picture as com_usr_picture,
usr.type as com_usr_type FROM aa_places as pl
LEFT JOIN aa_comments as com ON ( pl.id = com.place_id )
LEFT JOIN aa_users as usr ON (pl.userId = usr.id)

第二次选择失败。我需要做的是获取两种类型的用户:地点的用户所有者(用户名、用户电子邮件等)和评论的用户所有者

 (SELECT name as com_name, email as com_email, picture as com_picture
FROM aa_users
LEFT JOIN aa_comments ON aa_users.id = aa_comments.user_id)

我无法让它发挥作用。我应该改变什么???

最佳答案

您的内部选择位于主查询的选择中。这是合法的,但这样做时您只能返回一列(和一行)——您的查询将返回三列,并且可能返回许多行,因为没有条件。

我不完全清楚你想要做什么,但我认为这应该让你更接近:

SELECT 
pl.id, pl.latitude, pl.longitude, pl.userId, pl.time, pl.type, com.id as com_id, com.text, com.time as com_time,
com_usr.name as com_name, com_usr.email as com_email, com_usr.picture as com_picture,
usr.name as com_usr_name,
usr.email as com_usr_email,
usr.picture as com_usr_picture,
usr.type as com_usr_type
FROM aa_places as pl
LEFT JOIN aa_comments as com ON ( pl.id = com.place_id )
LEFT JOIN aa_users as com_usr ON (com.user_id=com_usr.id)
LEFT JOIN aa_users as usr ON (pl.userId = usr.id)

根据评论进行更新。

关于mysql - MySQL 查询格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20686847/

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