所以我在 mySQL 中有一个包含日期和金额的表。 日期从 2011~2013 运行,我想做的是: 找出所有 3 年的所有 31 天的 6 月每一天的平均值? 这是否有意义?
我有什么:
$query="select*from apple where date like '%06%'";
$result=mysql_query($query,$connect);
$sum=0
while ($apple=mysql_fetch_array($result)) {
$sum+=$apple["amount"];
}
$result=mysql_query("select count(*) from apple where dayname(date)='%06%'");
$co=mysql_result($result,0);
$avg=$sum/3;
echo $avg, "<br>";
?>
非常感谢您的帮助!谢谢你! :)
最佳答案
考虑改用 SQL 进行平均:
select date, avg(amount)
from apple
where month(date) = 6
group by date;
关于php - 试图使用 php 查找年份中每个日期的平均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24005687/