gpt4 book ai didi

mysql - friends表的pending friend request查询和其他表的抓取数据

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

要获取我使用的选定用户的待处理请求:

SELECT f1.asker_user_id AS friend_id
FROM friends AS f1
LEFT JOIN friends AS f2
ON f1.asked_user_id = f2.asker_user_id
AND f1.asker_user_id = f2.asked_user_id
WHERE f1.status = 1 AND f2.status IS NULL
AND f1.asked_user_id = 2

http://www.sqlfiddle.com/#!2/0f7a0d5/65它正确返回用户 3。VALUES (3,2,1)

但我想获取有关此用户 3 的更多数据。

我需要 users 表中的 name_surnameavatar。以及来自 connections 表的该用户的所有 word_id,作为返回,它会根据 words_en 显示 word word_id.

谢谢分配!

附注我试过这个:

SELECT a.name_surname,GROUP_CONCAT(Distinct w.word Order by w.word asc) AS words
FROM (
SELECT f1.asked_user_id AS friend_id,
f1.created,
u.name_surname,
u.avatar
FROM friends AS f1
LEFT JOIN friends AS f2 ON f1.asked_user_id = f2.asker_user_id
INNER JOIN users AS u ON f1.asked_user_id = u.id
AND f1.asker_user_id = f2.asked_user_id
WHERE f1.status = 1 AND f2.status IS NULL
AND f1.asker_user_id = 2
) a
LEFT JOIN connections c ON c.user_id = a.friend_id
LEFT JOIN words_en w ON c.word_id = w.id
GROUP BY 1;

最佳答案

根据这个问题和你之前的问题,我认为你可能正在寻找这样的东西:

SELECT u.name_surname, 
u.avatar,
GROUP_CONCAT(DISTINCT w.word Order by w.word asc) AS words
FROM users u
INNER JOIN
(
SELECT f1.asker_user_id AS friend_id
FROM friends AS f1
LEFT JOIN friends AS f2
ON f1.asked_user_id = f2.asker_user_id
AND f1.asker_user_id = f2.asked_user_id
WHERE f1.status = 1 AND f2.status IS NULL
AND f1.asked_user_id = 2
) a ON a.friend_id = u.id
LEFT JOIN connections c ON u.id = c.user_id
LEFT JOIN words_en w ON w.id = c.word_id
GROUP BY u.id;

sqlfiddle demo

关于mysql - friends表的pending friend request查询和其他表的抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19791301/

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