我在使用相关字段max
)获取provider_state
平均值时遇到问题。
我有一张桌子。其中有average_total_payments
字段用于付款。每行还有状态字段provider_state
。从下面的查询中我得到Max
Avg
,但我没有得到相关的provider_state
。
此查询的主要目的是为我提供具有最高付款平均值的州名称,包括付款金额。
的mysql_query
SELECT provider_state
,MAX(average) AS max_average
FROM ( SELECT provider_state
,AVG(average_total_payments) AS average
FROM gnomics
WHERE drg_definition LIKE '%$search%'
GROUP BY provider_state ) AS abc
请给我一些建议,了解相关领域的最佳途径是什么?
答案 0 :(得分:0)
如果您的问题是“请说明具有最高付款平均金额的州的名称,包括付款金额”。然后你可以这样解决:
SELECT provider_state, AVG(average_total_payments) AS average
FROM gnomics
WHERE drg_definition LIKE '%$search%'
GROUP BY provider_state
ORDER BY average desc
LIMIT 1;
答案 1 :(得分:0)
如果我理解了这个问题:
SELECT provider_state, field1, field2 ....
,MAX(average) AS max_average
FROM ( SELECT provider_state, field1, field2 ....
,AVG(average_total_payments) AS average
FROM gnomics
WHERE drg_definition LIKE '%$search%'
GROUP BY provider_state, field1, field2 ....
) AS abc
应该做的工作