我在 数据库 项目中使用 mysql,我有一个 mysql 表分类法。
我在 mysql 中需要条件为 tax_id = 1 和 tax_id = 2 的 post_id,如果我想要可用于加入 sql。
例子:
post_id | tax_id
------- | ------
1 | 1
1 | 2
2 | 1
2 | 3
我想要 postid 等于 condation taxid 等于 1 和 2
例如我使用这个 sql 但不工作:
SELECT * FROM `term_relationships` WHERE tax_id = 9 AND tax_id = 1120 ;
最佳答案
这是使用条件聚合
的一个选项:
select post_id
from term_relationships
group by post_id
having count(case when term_taxonomy_id in (9, 1120) then 1 end) = 2
关于mysql - 如何在 mysql 连接查询中使用一列中的两个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39262490/