我有以下 SQL 语句来计算基于 3 个 Wordpress 表的几个字段。我需要的是计算下面的语句中不起作用的SUM
和。AVG
我只需要在meta_key = image
. 这同样适用于AVG
公式,即 avg all meta_values when meta_key=odd
。
任何帮助深表感谢!
SELECT (user_nicename) AS user,
SELECT SUM(IF('meta_key' = 'image', 'meta_value' = '3279', 1,0)) AS won,
SELECT SUM(IF('meta_key' = 'image', 'meta_value' = '3280', 1,0)) AS lost,
COUNT('meta_key'='odd') AS total,
FORMAT (AVG('meta_key' = 'odd', 'meta_value'),1) AS 'average odd',
FORMAT (AVG ('meta_key' = 'bet', 'meta_value'),1) AS 'average bet',
SUM('meta_key' = 'roi', 'meta_value') AS ROI
FROM wp_postmeta pm, wp_posts p
INNER JOIN wp_posts p ON pm.post_id = p.ID
INNER JOIN wp_users u ON p.post_author = u.ID
WHERE Month(data) = MONTH(CURRENT_DATE)
GROUP BY (user_nicename)
ORDER BY ROI DESC