H
h2fcell
I have to create a query that counts the number of DISTINCT Agencies that
contribute to the sum of GrossSales grouped by Division.
The follow query returns the correct sum of GrossSales by Division, but
counts the number of contributing orders instead of DISTINCT contributing
Agencies.
SELECT qryStatisticalAgencySummary.Division,
Sum(qryStatisticalAgencySummary.Total) AS SumOfTotal,
Count(qryStatisticalAgencySummary.customer_id) AS CountOfcustomer_id
FROM qryStatisticalAgencySummary
GROUP BY qryStatisticalAgencySummary.Division;
Example: A Table with 20 orders each for $50 dollars, from 6 different
Agencies each pertaining to one of 3 Divisions should return something like
the below.
Division SumOfTotal Agencies
Division1, $300, 2
Division2, $450, 3
Division3, $250, 1
Instead my query returns:
Division SumOfTotal Agencies
Division1, $300, 6
Division2, $450, 9
Division3, $250, 5
I wish there was a CountDistinct() function. Any help to make this query
work is appreciated.
contribute to the sum of GrossSales grouped by Division.
The follow query returns the correct sum of GrossSales by Division, but
counts the number of contributing orders instead of DISTINCT contributing
Agencies.
SELECT qryStatisticalAgencySummary.Division,
Sum(qryStatisticalAgencySummary.Total) AS SumOfTotal,
Count(qryStatisticalAgencySummary.customer_id) AS CountOfcustomer_id
FROM qryStatisticalAgencySummary
GROUP BY qryStatisticalAgencySummary.Division;
Example: A Table with 20 orders each for $50 dollars, from 6 different
Agencies each pertaining to one of 3 Divisions should return something like
the below.
Division SumOfTotal Agencies
Division1, $300, 2
Division2, $450, 3
Division3, $250, 1
Instead my query returns:
Division SumOfTotal Agencies
Division1, $300, 6
Division2, $450, 9
Division3, $250, 5
I wish there was a CountDistinct() function. Any help to make this query
work is appreciated.