我正在尝试为特定产品提供最高报价。这是要约的后记:
Array ( [0] => stdClass Object ( [meta_id] => 507752 [post_id] => 95953
[5] => stdClass Object ( [meta_id] => 507757 [post_id] => 95953 [meta_key] => orig_offer_product_id [meta_value] => 2876 )
[9] => stdClass Object ( [meta_id] => 507761 [post_id] => 95953 [meta_key] => orig_offer_amount [meta_value] => 1.00 )
我正在尝试这样的事情:
echo $wpdb->get_var( "select max(orig_offer_amount->meta_value)
from $wpdb->postmeta
where meta_value=2876
and meta_key='orig_offer_product_id'
order by post_id limit 1" );
但它不起作用。
答案 0 :(得分:1)
也许你们中有些人也有同样的情况。当我发布一些问题时,我脑子里闪过光芒,我知道如何解决这个问题:)并且有解决方法:
global $wpdb;
echo $wpdb->get_var( " select max(meta_value)
from ".$wpdb->postmeta."
where meta_key='orig_offer_amount'
and meta_value!=''
and post_id in(
select p.post_id
from ".$wpdb->postmeta." as p
where p.meta_key='orig_offer_product_id' and
p.meta_value=2876)"
);