给定一个如下所示的表:
DATE USER TYPE DEPT
3/1/13 Team1 Add Finance
3/1/13 Team1 Add Collections
3/2/13 Team1 Delete Finance
3/2/13 Team1 Delete Finance
3/2/13 Team1 Delete Finance
3/3/13 Team1 Delete Collections
3/3/13 Team1 Change Finance
3/3/13 Team1 Change Finance
3/4/13 Team1 Add Finance
3/5/13 Team1 Delete Collections
我怎样才能得到这样的输出?
TYPE DEPT COUNT
Add Collections 1
Add Finance 2
Change Collections 0 (note: this line could be omitted if COUNT = 0)
Change Finance 2
Delete Collections 2
Delete Finance 3
我还需要指定 USER = Team1 和日期范围。到目前为止,我有以下内容,但它不起作用:
SELECT user, type, Count(*) AS Total
FROM table1
GROUP BY user, type
HAVING (((user)="Team1"));
这给了我:
USER TYPE Total
Team1 Add 3
Team1 Change 2
Team1 Delete 5
但不会按 DEPT 分解,我不确定如何指定日期范围。
一如既往,谢谢!!
编辑:我想我想通了:
SELECT User, Type, Dept, Count(*) AS Total
FROM Table1
WHERE (((Date) Between #3/1/2013# And #3/5/2013#))
GROUP BY User, Type, Dept
HAVING (((User)="Team1"));