我有以下查询:
SELECT DISTINCT `t`.*
FROM `wp_posts` AS `t`
LEFT JOIN `wp_postmeta` AS `age_restriction` ON `age_restriction`.`meta_key` = 'age_restriction' AND `age_restriction`.`post_id` = `t`.`ID`
LEFT JOIN `wp_postmeta` AS `_kksr_avg` ON `_kksr_avg`.`meta_key` = '_kksr_avg' AND `_kksr_avg`.`post_id` = `t`.`ID`
WHERE (
( `age_restriction`.`meta_value`='parental_guidance' AND `_kkr_avg`.`meta_value` BETWEEN '4.00' AND '5.00' ) AND
( `t`.`post_type` = "jokes" ) AND
( `t`.`post_status` IN ( "publish" ) )
)
ORDER BY `t`.`menu_order`, `t`.`post_title`, `t`.`post_date`
LIMIT 0, 15;
它是由一个名为PODS for Wordpress的插件生成的,它使用以下短代码来生成它:
[pods name="jokes" where="age_restriction.meta_value='parental_guidance' AND _kkr_avg.meta_value BETWEEN '4.00' AND '5.00'" template="joke"]
插件作者确实建议了我上面使用的解决方案。它导致我消失的错误,但没有得到结果。在WHERE子句中至少存在一个满足所有条件的条目(在wp_posts和wp_postmeta表中进行手动检查),因此我得出结论,我在pod短代码中做错了事。
我尝试过的事情
CAST()
至DECIMAL
(无结果)>= '4.00'
,但是遇到了MySQL语法错误(插件作者说,可能是因为Wordpress必须解析简码中的>=
)。有什么想法吗?
编辑:
如果我将查询更改为此,而没有评分,我将得到结果。
SELECT DISTINCT `t`.*
FROM `wp_posts` AS `t`
LEFT JOIN `wp_postmeta` AS `age_restriction` ON `age_restriction`.`meta_key` = 'age_restriction' AND `age_restriction`.`post_id` = `t`.`ID`
WHERE (
( `age_restriction`.`meta_value`='parental_guidance') AND
( `t`.`post_type` = "jokes" ) AND
( `t`.`post_status` IN ( "publish" ) )
)
ORDER BY `t`.`menu_order`, `t`.`post_title`, `t`.`post_date`
LIMIT 0, 15;
结果:
答案 0 :(得分:1)
扩大Uueerdo的注释,如果您正在寻找STRING为“ 4.0”和“ 5.0”,那么您将无法获得NUMERIC。如果该列是数字类型的数据类型,而不考虑精度,则只需删除值之间的引号。