我正在尝试根据 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
) );