Hello I have a field name team
and I would like to get the total amount that each team has been gatthered Im trying to echo the team name and total amount and group it by team but it doesn't work.
Here's my query:
$result = $wpdb->get_results("
SELECT
post.*, sum(meta.meta_value) as top_up_amount, meta.meta_value as team
FROM
$wpdb->posts as post
INNER JOIN
$wpdb->postmeta as meta
ON
post.ID = meta.post_id
AND
meta.meta_key = 'top_up_amount'
OR
meta.meta_key = 'team'
WHERE
post.post_status = 'publish'
AND
post.post_type = 'team_member'
GROUP BY
team
ORDER BY
top_up_amount DESC"
);
Can anyone please help?