trouble with query

G

Gary B

MASTER
Table: CHARGES
Fields: ChargesKey, ChargesDate

DETAIL
Table: SERVICES
Fields: ServicesKey, ServicesDate, SalesRep

I need to return the Count of CHARGES(ChargesKey) for each SalesRep

Thank you.
 
G

Gary B

MASTER
Table: CHARGES
Fields: ChargesKey, ChargesDate

DETAIL
Table: SERVICES
Fields: ServicesKey, ChargesKey, ServicesDate, SalesRep

I need to return the Count of CHARGES(ChargesKey) for each SalesRep

Thank you.
 
J

John Vinson

MASTER
Table: CHARGES
Fields: ChargesKey, ChargesDate

DETAIL
Table: SERVICES
Fields: ServicesKey, ChargesKey, ServicesDate, SalesRep

I need to return the Count of CHARGES(ChargesKey) for each SalesRep

Thank you.

SELECT SalesRep, Count([ChargesKey]) FROM Services GROUP BY SalesRep;

In the query grid, add just the Detail table; add the SalesRep and
ChargesKey fields; click the Greek Sigma icon (like a sideways M), and
change the default GroupBy under ChargesKey to Sum.
 
J

John Spencer (MVP)

This could be a two-query problem.

Query one.

SELECT Distinct ChargesKey, SalesRep
FROM Detail

Save that as qGetUnique and then

SELECT SalesRep, Count(ChargesKey)
FROM qGetUnique
GROUP BY SalesRep

In later versions of Access you can combine this into one query using a subquery.
 

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