我已经运行了一个MySQL查询(在wordpress php中):
\Mine\Baseclass
我现在想知道如何获得结果$myQuery = $wpdb->get_results('SELECT Opponent, ROUND(AVG(Avg_Points),2)
AS Avg_Points, ROUND(AVG(Plus_Minus),2) AS Avg_Plus_Minus
FROM ' . 'afl_defense_v_position' . ' WHERE Position = "MID"
AND Rank <= 1 AND Round >= 10 GROUP BY Opponent
ORDER BY Avg_Plus_Minus DESC')
列和Avg_Plus_Minus
列的平均值和标准偏差。
在将这些分组之前,我可以轻松获得Avg_Points
和Plus_Minus
的平均和标准偏差,但是在分组之后如何处理呢?我知道平均值是相同的,但标准差不是。
我想将这些值分配给php变量以进行进一步分析。
感谢您的帮助。
答案 0 :(得分:0)
一个简单的嵌套MySQL查询在这里起作用
$myQuery = $wpdb->get_results('SELECT STDDEV(t.Avg_Points) AS Std_Points
FROM (SELECT Opponent, ROUND(AVG(Points),2) AS Avg_Points,
ROUND(AVG(Plus_Minus),2) AS Avg_Plus_Minus FROM ' .
'afl_defense_v_position' . ' WHERE Position = "'. $select.'"
AND Rank <= '. $select3.' AND Round >= '. $select4.'
GROUP BY Opponent) AS t');