MS Access:查找每月最常用的用户

时间:2018-11-26 22:29:19

标签: database ms-access-2016

Access 2016的新功能,我正在编写一个查询以获取每月数据库中最普通的用户。

所以记录是

Month: Format([Date1],"mmmm")
TopUser: (SELECT TOP 1 [Table1]![ID] FROM [Table1] GROUP BY     
[Table1]![ID] order by COUNT([Table1]![ID]) DESC)

这是我的代码,每月汇总:

Month     TopUser
January   2
February  1
March     2
April     3

期望:

Month     TopUser
January   2
February  2
March     2
April     2

结果:

{{1}}

因此,我的代码返回的是总体上最常见的用户,而不是每个月。我不确定这是我误解的访问方面还是其查询。

1 个答案:

答案 0 :(得分:0)

尝试按月过滤:

Select 
    Format([Date1], "yyyymm") As YearMonth,
        (Select Top 1 T.ID 
        From Table1 As T
        Where Format(T.[Date1], "yyyymm") = Format(Table1.[Date1], "yyyymm")
        Group By ID
        Order By Count(T.ID) Desc) As TopID
From
    Table1
Group By
    Format([Date1], "yyyymm")