我正在用SQL表工作,并尝试获取我的数据集中在特定日期内每个零售商的交易号的不同计数。现在这就是我所拥有的:
SELECT COUNT (*), pos_table.Retailer
FROM pos_table
WHERE Month(Timestamp) = 3 AND Day(Timestamp) = 3 OR Day(Timestamp) = 4
Group By Retailer
这为我提供了每个零售商的计数,但是当我添加“ COUNT(DISTINCT pos_table.Transaction)代替COUNT(*)时,它将无法运行。
答案 0 :(得分:1)
访问不支持count(distinct [colunm])
,您可以尝试编写一个子查询来实现它。
select COUNT(t1.Transaction),t1.Retailer
from (
SELECT DISTINCT t1.Transaction,t1.Retailer
FROM pos_table AS t1
WHERE Month(t1.Timestamp) = 3 AND Day(t1.Timestamp) = 3 OR Day(t1.Timestamp) = 4
) AS t1
GROUP BY t1.Retailer