Better Example of Count() Query

G

Gary B

MASTER Table: CHARGES
Fields: ChargesKey, ChargesDate
Data: Row1 = 1, 05/25/2004

DETAIL Table: SERVICES
Fields: ServicesKey, ChargesKey, ServicesDate, SalesRepKey
Data: Row1 = 1, 1, 05/25/2004, 5
Row2 = 2, 1, 05/25/2004, 5

I need to return the Count of CHARGES(ChargesKey) for each SalesRepKey. In
the above example, the result should be 1
 
M

Michel Walsh

Hi,

In Northwind, the following will count, by country, the number or distinct
cities and the total number of records (by country):



TRANSFORM COUNT(*) As countCity
SELECT Customers.Country,
COUNT(countCity) As DistinctCount,
COUNT(*) As TotalCount
FROM Customers
GROUP BY Country
PIVOT city IN( NULL)


(adapted from an original presentation by Steve Dassin).


In your case, it seems country <-> SalesRepKey and city <-> ChargesKey.



Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top