gpt4 book ai didi

Mysql左连接: show rows based on another attribute from the joined table

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

我有下表:

   Pools                         Members                             User
----------------------------------------------------------------------------------
id name id pool_id user_id id name
----------------------------------------------------------------------------------
1 abc 1 1 101 101 test1
2 xyz 2 1 102 102 test2
3 2 105 105 test5
4 2 106 106 test6

当用户登录时,他应该查看他不是其成员的那些池的列表,例如,如果 ID 为 101 的用户登录,则应显示以下结果。

Pool              Members
xyz 2 members

最佳答案

可能是你想要的

SELECT name AS Pool,
count(pool_id) AS Members
FROM Pools
JOIN Members ON Pools.id=Members.pool_id
WHERE Pool.id NOT IN
(SELECT pool_id
FROM Members
WHERE user_id=101)
GROUP BY Member.pool_id

关于Mysql左连接: show rows based on another attribute from the joined table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24925562/

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