我已经有一个类似的查询:
SELECT max(cast(meta_value as unsigned)) AS max_racer_nr FROM wp_postmeta WHERE meta_key='racer_nr'
我需要获得racer_nr
介于1 - 99或100 - 199或200 - 999之间的最大值,具体取决于赛车手所属的类别。
SELECT MAX(CAST(`meta_value` AS unsigned)) AS `max_racer_nr` FROM `wp_postmeta` WHERE `meta_key` = 'racer_nr' AND `meta_value` BETWEEN 1 AND 99;
或者
SELECT MAX(CAST(`meta_value` AS unsigned)) AS `max_racer_nr` FROM `wp_postmeta` WHERE `meta_key` = 'racer_nr' AND `meta_value` >= 1 AND `meta_value` <= 99;
您只需要根据赛车手的类别更改 PHP 代码中的值。除非我误解了你需要什么。