Access 2010:同一查询中的Count和Distinct Count

时间:2018-01-09 20:24:50

标签: sql ms-access ms-access-2010

我正在处理Access 2010中的一个查询,该查询旨在汇总一个人完成的项目和项目任务的数量。

例如:

Person    |    Project    |    Project Task
1                1                1
1                1                2
1                2                1
2                1                1
2                1                2

我希望它返回:

Person    |    Project(s)    |    Project Task(s)
1                 2                  3
2                 1                  2
Total             3                  5

现在我的SQL看起来像这样:

SELECT Person, Project, Count(Project Task) AS Project Task
FROM table 
GROUP BY Person, Project
ORDER BY Person;

返回:

Person    |    Project    |    Project Task(s)
1                 1                  2
1                 2                  1
2                 1                  2
Total             3                  5

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

这应该有效:

select person, count(project), sum(projectTask) from 
(
    select person,  project, count(projectTask) as projectTask
    from table
    group by person, project
)
group by person   
order by person