MySQL GROUP BY和SUM值

时间:2021-11-23 01:30:24

I have a MySQL table that containes the following data:

我有一个包含以下数据的MySQL表:

filer            time               name        size-percentage-used  disk-count
filer01a  2012-01-19 05:59:02  aggr0                     96               3
filer01a  2012-01-19 05:59:02  ncna01a_aggr01            97              42
filer01a  2012-01-19 05:59:02  ncna01a_aggr02            96              22
filer01a  2012-01-19 05:59:02  ncna01a_aggr03             0              22
filer01a  2012-01-19 12:00:01  aggr0                     96               3
filer01a  2012-01-19 12:00:01  ncna01a_aggr01            97              42
filer01a  2012-01-19 12:00:01  ncna01a_aggr02            96              22
filer01a  2012-01-19 12:00:01  ncna01a_aggr03             0              22
filer01a  2012-01-20 12:00:01  aggr0                     96               3
filer01a  2012-01-20 12:00:01  ncna01a_aggr01            97              42
filer01a  2012-01-20 12:00:01  ncna01a_aggr02            96              22
filer01a  2012-01-20 12:00:01  ncna01a_aggr03             0              22
filer01a  2012-01-21 12:00:01  aggr0                     96               3
filer01a  2012-01-21 12:00:01  ncna01a_aggr01            97              42
filer01a  2012-01-21 12:00:01  ncna01a_aggr02            96              22
filer01a  2012-01-21 12:00:01  ncna01a_aggr03             0              22
filer01a  2012-01-22 12:00:02  aggr0                     96               3
filer01a  2012-01-22 12:00:02  ncna01a_aggr01            97              42
filer01a  2012-01-22 12:00:02  ncna01a_aggr02            96              22
filer01a  2012-01-22 12:00:02  ncna01a_aggr03             9              22
...

The list of filers goes from 01 to 102 and time is updated daily. I need a query that will provide filer, sum(disk-count) as DDMs, size-percentage-used, and max(time).

文件管理器列表从01到102,每天更新时间。我需要一个查询,它将提供文件管理器,总和(磁盘计数)作为DDM,大小百分比使用和最大(时间)。

The out put I'm looking for would be:

我正在寻找的输出将是:

 filer    DDMs     size-percentage-used  time                
 ncna01a  89                         96  2012-01-19 05:59:02
 ncna01a  89                         96  2012-01-19 05:59:02
 ncna02a  89                         96  2012-01-19 05:59:02
 ...

I am a total MySQL newbie and any and all help is appreciated.

我是一个完整的MySQL新手,任何和所有的帮助表示赞赏。

1 个解决方案

#1


0  

From my understanding, you will need something like the following query:

根据我的理解,您将需要类似以下查询的内容:

SELECT SUM(disk-count) AS ddms, 
       AVG(size-percentage-used) AS percent_used, 
       MAX(time) as max_time 
FROM filers 
GROUP BY filer

#1


0  

From my understanding, you will need something like the following query:

根据我的理解,您将需要类似以下查询的内容:

SELECT SUM(disk-count) AS ddms, 
       AVG(size-percentage-used) AS percent_used, 
       MAX(time) as max_time 
FROM filers 
GROUP BY filer