创建一个查询以按日期提取唯一的事务ID

时间:2015-08-25 22:04:45

标签: sql count distinct

我不熟悉使用SQL在访问中创建查询,但必须使用它在表中创建一个独特的事务ID计数。我能够让它工作,但我无法将其纳入我的整体查询。

下面是代码 - 我基本上总结了表中的几列,还添加了一个列,显示了来自同一个表的不同的发票ID数。有一个表被连接起来以引入一些额外的字段。

SELECT "Q" & [Quarter] & " " & [Year] AS QUARTER, [0_Time].MONTH, [0_Time].WEEK, Sum(Abracadabra_Sales.Qty) AS SumOfQty, Sum(Abracadabra_Sales.[Total Sell]) AS [SumOfTotal Sell], Sum(Abracadabra_Sales.[Total Sell]-[Total Cost]) AS [GM$], Avg(Abracadabra_Sales.[Total Sell]/[Qty]) AS AUR, Avg(Abracadabra_Sales.[Total Cost]/[Qty]) AS AUC, 

count([Invoice ID]) AS TransCount
FROM (SELECT DISTINCT [Invoice ID] FROM Abracadabra_Sales)

FROM 0_Time INNER JOIN Abracadabra_Sales ON [0_Time].DAY = Abracadabra_Sales.Date
GROUP BY "Q" & [Quarter] & " " & [Year], [0_Time].MONTH, [0_Time].WEEK;

0 个答案:

没有答案