MySQL自动生成统计帧数据

时间:2008-12-24 05:25:31

标签: mysql average

我有一个表包含日期,距离和TimeForDistance ...

有没有办法使用MySQL语句计算每月平均速度?

真的很感激任何帮助!

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找这样的东西:

SELECT
    YEAR(my_date) as my_year, 
    MONTH(my_date) as my_month, 
    sum(Distance) / sum(TimeForDistance) AS velocity 
FROM your_table 
GROUP BY my_year, my_month
ORDER BY my_year, my_month