【问题标题】:The highest offer in woocommercewoocommerce中的最高报价
【发布时间】:2019-01-28 13:34:45
【问题描述】:

我正在尝试获得特定产品的最高报价。这是offer的postmeta:

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" );

但它不起作用。

【问题讨论】:

  • 出现错误?首先在 phpmyadmin 中尝试您的查询select max(orig_offer_amount->meta_value) from yourtable where meta_value=2876 and meta_key='orig_offer_product_id' order by post_id limit 1 检查是否工作?但是orig_offer_amount->meta_value 是什么?
  • 非常感谢,但我已经解决了问题,见下文。
  • 有人可以解释为什么有人给我的问题吗?我是这个网站的新手,我不知道发生了什么。
  • 不知道 .... ...

标签: php mysql woocommerce


【解决方案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)" 
  );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2017-05-30
    • 2021-03-22
    • 2018-05-25
    • 2020-11-12
    • 1970-01-01
    • 2016-01-26
    相关资源
    最近更新 更多