mysql - 我需要从 3 个分类法(个人资料类别、县、部门)中获取帖子数据
问题描述
下面的查询正在使用一种分类法
SELECT *
FROM bb_posts AS p
LEFT JOIN bb_term_relationships AS r ON (p.ID = r.object_id)
INNER JOIN bb_term_taxonomy AS x ON (r.term_taxonomy_id = x.term_taxonomy_id)
INNER JOIN bb_terms AS t ON (r.term_taxonomy_id = t.term_id)
WHERE p.post_type IN ('post', 'profile')
AND p.post_status = 'publish'
AND x.taxonomy = 'profile-category'
AND t.term_id = '577'
AND x.taxonomy = 'county'
AND t.term_id = '804'
AND x.taxonomy = 'Sector'
AND t.term_id = '830'
ORDER BY p.post_date DESC
如何从 3 个分类法中获取帖子数据?
解决方案
这是一种可能的解决方案
SELECT * FROM bb_posts 左连接 bb_term_relationships ON (bb_posts.ID = bb_term_relationships.object_id) 左连接 bb_term_relationships AS tt1 ON (bb_posts.ID = tt1.object_id) 左连接 bb_term_relationships AS tt2 ON (bb_posts.ID = tt2.postmeta_id) 内连接 bb_posts.ID = tt1.object_id开启(bb_posts.ID = bb_postmeta.post_id)其中 1=1
AND ( bb_term_relationships.term_taxonomy_id IN (689) AND tt1.term_taxonomy_id IN (798) AND tt2.term_taxonomy_id IN (828) ) AND ( ( bb_postmeta.meta_key = 'sector' AND bb_postmeta.meta_value LIKE '%Wheelchair%' ) ) AND bb_posts .post_type IN ('allusers', 'profile') AND (bb_posts.post_status = 'publish' OR bb_posts.post_status = 'acf-disabled' OR bb_posts.post_author = 1 AND bb_posts.post_status = 'private') 按 bb_posts 分组。 ID ORDER BY bb_posts.ID DESC LIMIT 0, 12
推荐阅读
- ios - 具有动态大小单元格间距问题的 UICollectionViewCell
- java - 如何使用 org.testng.TestNG 将参数输入到此测试运行中?
- hive - 选择另一个表中不存在的列sql中的多个列
- rest - Spring-Boot Junit Test Rest 调用给出异常
- vue.js - 关闭语义模式后,Vue UI 未使用 axios 更新
- linux - 在 Docker 上运行时,如何应用 IBM MQ 操作系统 (Linux) 调优指南?
- xml - XPath contains() 不起作用
- python - 使用 Maplotlib 自定义子图方向和大小
- asp.net-mvc - 交换 Azure Web App 时的 Code First 数据库迁移
- python - 在每个 HealPix 像素的中心写一个数字