access获取最大值及其发生的月份和时间

Getting the max value and the month and hour it occurred in access

**我有以下 table:

ClientID  ClientName  Power   Date        Month Hour
123456    aaa         558     11/2/2014   11    5
123456    aaa         1558    11/2/2014   11    6
123456    aaa         1238    11/2/2014   11    7
123456    aaa         458.48  11/2/2014   11    8
789000    bbb         800.48  11/2/2014   11    5
789000    bbb         190.10  11/2/2014   11    6
789000    bbb         909     11/2/2014   11    7
789000    bbb         405     11/2/2014   11    8
777888    ccc         702     11/2/2014   11    1

我尝试获取特定月份和年份的 clientid、clientname、max(power)、月份和小时,我尝试了几次查询,我越接近使用:

SELECT clientid, clientname, max(max_power), date, hour
FROM (SELECT clientid, clientname, max(Power) AS max_power, date, hour FROM 
tabledata WHERE month(date) = 11 and year(date) = 2014 
GROUP BY clientid, clientname, date, hour)  AS t
GROUP BY clientid, clientname, date, hour;

但是我得到了所有不同的时间,我只想要每个客户的最大值的日期和时间。

谁能帮帮我。

像这样:

select A.clientid, A.clientname, A.power, A.date, A.hour
from tabledata A
JOIN
(
    SELECT clientid, max([power]) as max_power
    from tabledata
    group by ClientID
) as B on A.ClientID = b.ClientID and A.[power] = B.max_power