访问查询以按天求和并按小时/分钟计数

Access Query to sum by day and count by hour / minute

我正在尝试使用以下数据编写查询。我的挑战是每天,我需要计算“105”出现在 Col A 和“100”出现在 Col B 的次数。我不需要计算每个实例“105”出现,而是每分钟“105”出现。同样,Col B 和“100”

Date           Time      A   B
1/20/2021   1:06:12 AM  105 100
1/20/2021   1:06:16 AM  105 100
1/20/2021   1:06:20 AM  105 100
1/20/2021   2:28:12 AM  105 100
1/20/2021   2:28:16 AM  105 100
1/20/2021   2:28:20 AM  105 100
1/20/2021   3:50:08 AM  105 10
1/20/2021   3:50:12 AM  105 10
1/20/2021   3:50:16 AM  105 10
1/20/2021   5:12:04 AM  105 10
1/20/2021   5:12:08 AM  105 10
1/20/2021   5:12:12 AM  105 10

详情:

Time  A  B
1:06  1  1
2:28  1  1
3:50  1  0
5:12  1  0

查询结果:

Date      A    B
1/21/20   4    2

如有任何建议,我们将不胜感激。

一种方法是对每一列分别使用distinct。然后汇总:

select date, sum(a), sum(b)
from (select distinct date, hour(time) as hh, minute(time) as mm, 1 as a, 0 as b
      from t
      where a = 105
      union all
      select distinct date, hour(time) as hh, minute(time) as mm, 0 as a, 1 as b
      from t
      where b = 100
     ) t
group by date;