douhong6187 2017-11-09 19:22
浏览 43

有人可以告诉我这个查询有什么问题..? [关闭]

SELECT p.post_title FROM wp_posts p
LEFT JOIN wp_term_relationships tr on (p.ID = tr.object_id)
LEFT JOIN wp_term_taxonomy tt on (tr.term_taxonomy_id = tt.term_taxonomy_id)
LEFT JOIN wp_term_taxonomy tt2 on (tr.term_taxonomy_id = tt2.term_taxonomy_id)
WHERE 
tt2.term_id IN( 36, 32)
AND tt.term_id = 33
AND p.post_type = 'post'

Actually, i have two different taxonomy (namely status and category) each of those has many terms. there i have to check in one certain category term (that term_id 33) has how many posts whose statuses terms term_id 36 or 32.

Actually, i need to apply the condition to the same column ( of wp_term_taxonomy table) two times.

Above query return nothing.Guys, please help me out.

  • 写回答

1条回答 默认 最新

  • dounao4179 2017-11-09 19:25
    关注

    Don't use columns related to LEFT JOIN TABLE in WHERE condition otherwise these work as an INNER JOIN so

    SELECT p.post_title FROM wp_posts p
    LEFT JOIN wp_term_relationships tr on (p.ID = tr.object_id)
    LEFT JOIN wp_term_taxonomy tt on (tr.term_taxonomy_id = tt.term_taxonomy_id) 
            AND tt.term_id = 33
    LEFT JOIN wp_term_taxonomy tt2 on (tr.term_taxonomy_id = tt2.term_taxonomy_id) 
            AND tt2.term_id IN ( 36, 32)
      WHERE p.post_type = 'post'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败