我知道如何做一個計數明顯時,它的簡單是這樣的:MS ACCESS SQL查詢計數DISTINCT
SELECT AllItemsDateRange.Processors.ACH_Processor, COUNT(*) AS NumDays
FROM (SELECT DISTINCT AllItemsDateRange.Processors.ACH_Processor, AllItemsDateRange.SubmitDate FROM AllItemsDateRange) AS T1
GROUP BY AllItemsDateRange.Processors.ACH_Processor;
但是,我不知道如何添加一個計數明顯時,它沒有一個更復雜的查詢影響其他數據。在下面的查詢中,我希望最後一項(NumDays)爲AllItemsDateRange.Processors.ACH_Processor,AllItemsDateRange.SubmitDate的不同計數。
SELECT AllItemsDateRange.Processors.ACH_Processor, AllItemsDateRange.ExposureLimit, AllItemsDateRange.Footprint, Sum(IIf([AllItemsDateRange].[DebitAmount]>0,1,0)) AS Debits, Sum(AllItemsDateRange.DebitAmount) AS DebitAmt, Sum(IIf([AllItemsDateRange].[CreditAmount]>0,1,0)) AS Credits, Sum(AllItemsDateRange.CreditAmount) AS CreditAmt, Sum(IIf(([AllItemsDateRange].[ReturnDate]>0) And ([AllItemsDateRange].[DebitAmount]>0),1,0)) AS DebitReturns, Sum(IIf(([AllItemsDateRange].[ReturnDate]>0) And ([AllItemsDateRange].[CreditAmount]>0),1,0)) AS CreditReturns, Sum(IIf([AllItemsDateRange].[ReturnDate]>0,[AllItemsDateRange].[CreditAmount]+[AllItemsDateRange].[DebitAmount],0)) AS ReturnAmt, Sum(IIf((([AllItemsDateRange].[ReturnCode]="R05") Or ([AllItemsDateRange].[ReturnCode]="R07") Or ([AllItemsDateRange].[ReturnCode]="R10") Or ([AllItemsDateRange].[ReturnCode]="R29") Or ([AllItemsDateRange].[ReturnCode]="R51")) And ([AllItemsDateRange].[DebitAmount]>0),1,0)) AS UnauthorizedReturns, Sum(IIf((([AllItemsDateRange].[ReturnCode]="R05") Or ([AllItemsDateRange].[ReturnCode]="R07") Or ([AllItemsDateRange].[ReturnCode]="R10") Or ([AllItemsDateRange].[ReturnCode]="R29") Or ([AllItemsDateRange].[ReturnCode]="R51")) And ([AllItemsDateRange].[DebitAmount]>0),[DebitAmount],0)) AS UnauthorizedReturnAmt, COUNT(AllItemsDateRange.SubmitDate) AS NumDays
FROM AllItemsDateRange
GROUP BY AllItemsDateRange.Processors.ACH_Processor, AllItemsDateRange.ExposureLimit, AllItemsDateRange.Footprint
ORDER BY AllItemsDateRange.Footprint, AllItemsDateRange.ExposureLimit DESC , AllItemsDateRange.Processors.ACH_Processor DESC;
編輯: [AllItemsDateRange]基本上是交易的列表。每筆交易都有一個日期。我想通過ACH_Processor彙總數據。因此,獲得借方和貸方的總數和總計很容易。最困難的部分是獲取ACH_Processor處理事務的不同日期的計數,以便稍後可以計算每日平均值。
你想在第二個查詢中的不同計數,只是ACH_Processor計數(*)爲天數? – xQbert
http://stackoverflow.com/questions/11880199/how-do-i-count-unique-items-in-field-in-access-query – xQbert
我基本上想要包含在第二個查詢結果中的第一個查詢(就位的NumDays)。那有意義嗎? – tgro