0
我有這個疑問:找到一個MySQL查詢結果的字段的最大值
select
id_re_usr,
year(time) as AYear,
DAYOFYEAR(time) as ADay,
DATE_FORMAT(time, "%m-%d-%y") as date,
count(*) as TotalPerDay
from numrequest
where id_re_usr = "u1"
group by id_re_usr, AYear, ADay
order by AYear, ADay
它輸出像
date TotalPerDay
------------------------
01-01-87 1
01-09-12 5
02-09-12 17
03-09-12 1
我怎麼能找到的最大TotalPerDay不改變電流輸出通過使用PHP或更改查詢。
我試圖做到這一點,它的工作原理
$max=0;
while($row=mysql_fetch_array($results)){
if($max<$row['TotalPerDay']){ $max= $row['TotalPerDay'];}
}
,但是是不是有直接的方式來做到這一點?
如果修改查詢,輸出應爲
date TotalPerDay max
----------------------------------------
01-01-87 1 17
01-09-12 5 17
02-09-12 17 17
03-09-12 1 17
'選擇MAX(TotalPerDay)從myTable的其中1 = 1組由date' – 2012-02-09 12:14:06
嘗試這樣做,沒有工作:'(選擇最大(COUNT(*))從numrequest其中id_re_usr = 「U1」 組(時間),DAYOFYEAR(時間)),作爲最大值' – 2012-02-09 12:24:17
'從numrequest中選擇max(count(*)),其中id_re_usr =「u1」group by id_re_usr,year(time),DAYOFYEAR – 2012-02-09 12:40:43