0

我正在尝试根据 Wordpress meta_values 计算产量,并且我正在使用下面的 MySQL 语句,但它不起作用。SUM(returned.meta_value+staked.meta_value)-SUM(staked.meta_value))/SUM(staked.meta_value))*100) 不返回任何值。

有人可以帮我解决下面的表达式有什么问题。

谢谢你。

global $post;
$post_author = $post->post_author;
$post_status = 'publish';
$yield = $wpdb->get_var( $wpdb->prepare(
    "
    SELECT (ROUND((((SUM(returned.meta_value+staked.meta_value)-SUM(staked.meta_value))/SUM(staked.meta_value))*100),2),2)
    FROM {$wpdb->posts} p
    JOIN {$wpdb->users} u ON p.post_author = u.ID
    LEFT JOIN {$wpdb->postmeta} staked
        ON p.ID = staked.post_id AND staked.meta_key = 'staked'
    LEFT JOIN {$wpdb->postmeta} returned 
        ON p.ID = returned.post_id AND returned.meta_key = 'returned'
    WHERE p.post_author = %s AND p.post_status = %s
    ",
    $post_author, $post_status
    ) );
4

1 回答 1

0

您的查询没有意义。该select语句使用别名balancebet. 该from子句具有别名pmposts.

你是这个意思吗?

SELECT (ROUND((((SUM(pm.meta_value+pm.meta_value)-SUM(pm.meta_value))/SUM(pm.meta_value))*100),2),2)
FROM {$wpdb->postmeta} pm INNER JOIN
     {$wpdb->posts} p
     ON pm.post_id = p.ID
WHERE pm.meta_key = %s AND pm.meta_key1 = %s AND p.post_author = %s AND
      Month(p.post_date) = MONTH(CURRENT_DATE) AND p.post_status = %s 
于 2013-04-22T14:31:37.153 回答