【发布时间】:2015-04-01 22:36:52
【问题描述】:
我正在使用 Wordpress 并尝试从我自己的一个表中选择与本机 wp_postmeta 表中的值相对应的值。
我的表被称为“wellwishertable”,我想从 Wellwisher 表中找到所有 ID(以便我可以计算它们)...
1) wellwishertable 'associatedID' 字段在 wp_postmeta post_id 中
2) wellwishertable 'associatedAuthorID' 与 $userID 变量相同
3) 良好的“许可”正在等待中
4) wp_postmeta meta_key 'status' 不等于 meta_value 'open'
5) wp_postmeta meta_key 'freeze' 不等于 meta_value 'frozen'
我已经走了这么远......
"SELECT DISTINCT wellwisher.ID FROM wellwishertable wellwisher
INNER JOIN wp_postmeta ON (wellwisher.associatedID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_postmeta.post_id = mt1.post_id)
INNER JOIN wp_postmeta AS mt2 ON (wp_postmeta.post_id = mt2.post_id)
WHERE wellwisher.associatedAuthorID=".$userID."
AND wellwisher.permission ='pending'
AND ( (mt1.meta_key = 'status' AND mt1.meta_value != 'open') AND
(mt2.meta_key = 'freeze' AND mt2.meta_value != 'frozen') );
这似乎“几乎”工作,除了它不计算 wp_postmeta 表中没有“冻结”元键的记录。我希望它计算任何未“冻结”的记录,无论它是否存在(只要“状态”不是“打开”)。
有人能指出我正确的方向吗?
【问题讨论】: