我有以下代码,我想根据用户的总余额只获得用户的联赛排名。我怎样才能做到这一点?
// Set League Rank by User
global $post;
$post_author = $post->post_author;
$post_status = 'publish';
$meta_key = 'balance';
$rank = $wpdb->get_var( $wpdb->prepare(
"
SELECT *, @rownum := @rownum + 1 from
(
SELECT
SUM(meta_value) as balance,
FROM {$wpdb->postmeta} pm
INNER JOIN {$wpdb->posts} p ON pm.post_id = p.ID
JOIN (SELECT @curRow := 0) r;
WHERE pm.meta_key = %s AND p.post_author = %s AND p.post_status = %s
order by balance desc)x, (SELECT @rownum := 0) r
",
$meta_key, $post_author, $post_status
) );
有人可以帮助我吗?
谢谢你。