2013-03-27 163 views
0

我有一個MySQL表containes以下數據:MySQL的GROUP BY和和值

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 
... 

文件管理器的例子不勝枚舉,從01到102和時間每天更新。我需要一個查詢,它將提供filer,總和(disk-count)作爲DDM,大小百分比和最大值(時間)。

的出來把我在尋找將是:

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 
... 

我是一個總的MySQL新手,任何和所有幫助表示讚賞。

回答

0

從我的理解,你需要像下面的查詢:

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