gpt4 book ai didi

MySql 多对多仅选择连接行处的固定行

转载 作者:行者123 更新时间:2023-11-30 00:34:44 25 4
gpt4 key购买 nike

我这里有一个数据库

第一个表是对话表

___________________________
| id | conversation Name |
__________________________
| 1 | member and officer |
___________________________
| 2 | member and guests |
___________________________

第二个表是用户表

_________________
| id | name |
_________________
| 1 |member |
_________________
| 2 |officer |
_________________
| 3 |guest |
_________________

第三个表是conversation_user_involved表

_________________________________
| id_conversation | id_user |
_________________________________
| 1 | 1 |
_________________________________
| 1 | 2 |
_________________________________
| 2 | 1 |
_________________________________
| 2 | 3 |
_________________________________

问题是如何根据用户选择对话。

假设输入用户参数为 1 和 2,则意味着用户 1 是成员,2 是官员。如何选择对话成员和官员?

我尝试过“IN”查询,但没有成功。

最佳答案

未经测试:

select     id_conversation, conversation_Name
from conversation_user_involved
inner join conversation on (id_conversation = conversation.id)
where id_user in (1, 2)
group by id_conversation
having count(id_conversation) = 2

关于MySql 多对多仅选择连接行处的固定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22269862/

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