查询单个日期,按条件计算值
Query with individual dates, counting values by criteria
我想要一个只显示单个日期的查询(因此不会出现单个日期 twice/multiple),计算给定日期的记录数,并进一步计算另一个字段满足其他条件的记录数:
Date | total amount | Field2 = "Aaa" | Field2 = "Bbb" | Filed2 = ....
10.7.18 | 32 | 2 | 3 | ...
11.7.18 | 20 | 5 | 2 | ...
我的方法是将其 属性 设置为 "unique values" 到 "yes" 的查询,然后我两次添加日期字段,首先将其功能设置为 "group by",第二个函数设置为"count";这只给我个人日期和设定日期的记录数。到目前为止一切顺利。
现在我添加"Field2",将其函数设置为"count",并将条件添加到“=Value("Aaa")”。这将显示一个空的记录列表。
试试这个:
Select
[Date],
Sum(Amount) As TotalAmount,
Sum(Abs(Field2 = "Aaa")) As CountA,
Sum(Abs(Field2 = "Bbb")) As CountB,
Sum(Abs(Field2 = "Ccc")) As CountC
From
YourTable
Group By
[Date]
如果您只需要总计 count,请使用:
Select
[Date],
Count(*) As TotalCount,
Sum(Abs(Field2 = "Aaa")) As CountA,
Sum(Abs(Field2 = "Bbb")) As CountB,
Sum(Abs(Field2 = "Ccc")) As CountC
From
YourTable
Group By
[Date]
我想要一个只显示单个日期的查询(因此不会出现单个日期 twice/multiple),计算给定日期的记录数,并进一步计算另一个字段满足其他条件的记录数:
Date | total amount | Field2 = "Aaa" | Field2 = "Bbb" | Filed2 = ....
10.7.18 | 32 | 2 | 3 | ...
11.7.18 | 20 | 5 | 2 | ...
我的方法是将其 属性 设置为 "unique values" 到 "yes" 的查询,然后我两次添加日期字段,首先将其功能设置为 "group by",第二个函数设置为"count";这只给我个人日期和设定日期的记录数。到目前为止一切顺利。
现在我添加"Field2",将其函数设置为"count",并将条件添加到“=Value("Aaa")”。这将显示一个空的记录列表。
试试这个:
Select
[Date],
Sum(Amount) As TotalAmount,
Sum(Abs(Field2 = "Aaa")) As CountA,
Sum(Abs(Field2 = "Bbb")) As CountB,
Sum(Abs(Field2 = "Ccc")) As CountC
From
YourTable
Group By
[Date]
如果您只需要总计 count,请使用:
Select
[Date],
Count(*) As TotalCount,
Sum(Abs(Field2 = "Aaa")) As CountA,
Sum(Abs(Field2 = "Bbb")) As CountB,
Sum(Abs(Field2 = "Ccc")) As CountC
From
YourTable
Group By
[Date]