我如何在mySQL中编写一个查询,显示一天中的平均行程?



我有一个id列表和他们旅行的详细信息。我想知道每个ID每天平均旅行多少次,但我不知道如何编写这个查询。表中的数据是这样的:

<表类> ID Ride_id 日期 tbody><<tr>11232022-3-411242022-3-411112021-2-825842019-4-1822562019-4-1828052020-5-821272020-5-824572020-5-831002021-4-731012021-4-732022021-5-1737412021-5-17

首先计算每个id每天的出行次数,然后对这些次数求平均值。

select id, avg(trips)
from (select id, count(*) as trips
from trips
-- where id in(1,2,3)
group by id, date) t
group by id

如果需要,您可以取消子查询中的where子句的注释,以过滤特定的id…

最新更新