获取mySQL工作台查询的平均时间

问题描述 投票:0回答:1

我在mySQL工作台中有一个表,它有几列和1100万行。

其中一列是以下格式的时间戳:

2014-01-01 00:12:54

还有另一个专栏,我正在进行分组。

我的查询目前看起来像这样:

SELECT app_type, count(series_id) as 'Num of Series Downloaded' from access_log
WHERE action = 'download' AND org_id != 1
GROUP BY app_type;

这产生了一个结果:

enter image description here

我想要做的是获得每月下载的系列平均数(series_id),因为我有一个时间列。请记住,有5年的数据和1100万行。

理想情况下,结果的格式如下:

enter image description here

我的查询是什么样的格式化结果,就像我想要实现的那样?

mysql sql mysql-workbench
1个回答
0
投票

我想你只想要一个基本的聚合查询:

SELECT DATE_FORMAT(`timestamp`, '%Y-%m') as yyyymm,
       SUM(app_type = 'API') as API,
       SUM(app_type = 'Web') as Web,
       SUM(app_type = 'Excel') as Excel
FROM access_log
WHERE `action` = 'download' AND org_id <> 1
GROUP BY yyyymm;
© www.soinside.com 2019 - 2024. All rights reserved.