【发布时间】:2018-02-22 17:18:51
【问题描述】:
我有三张桌子:
posts (id, content)
posts_tags (posts_id, tags_id)
tags (id, tag)
如何选择所有具有(至少)2 个特定标签的帖子(比如说 id 为 1 和 2 的标签)?
例如帖子表:
id content
---- -------
1 post1
2 post2
3 post3
标签表:
id tag
---- ------
1 tag1
2 tag2
3 tag3
posts_tags 表:
posts_id tags_id
---------- ---------
1 1
1 2
2 1
3 1
3 2
3 3
然后我期待以下结果:
id content
---- ---------
1 post1
3 post3
使用 ID 3 发布(因为它有标签 1、2 和 3)和使用 id 1 发布(因为它有带有 id 1 和 2 的标签)但没有发布 2,因为它没有带有 id 2 的标签.
假设我无法更改表结构。
【问题讨论】:
-
请Edit您的问题并添加一些sample data 和基于该数据的预期输出。 Formatted text 请no screen shots。 edit 您的问题 - 请不要在 cmets 中提供邮政编码或其他信息。