Query to count on multiple fields

W

WembleyBear

Hi

I have a query that is based on a table called TARGETS which returns the
number of targets in the table that are marked as "bad", and then grouped by
user. The code for this query is:

SELECT TARGETS.[User Name], Count(TARGETS.Bad) AS CountOfBad
FROM TARGETS
GROUP BY TARGETS.[User Name]
HAVING (((Count(TARGETS.Bad))=True))
ORDER BY Count(TARGETS.Bad) DESC;

What I want to do in addition to the count of bad target records created by
user name, is to show the total number of records created by each user, so
that the result is something like:

Created Bad
Mary Jones 17 4
Bob Smith 12 3
etc

What is the best way to do this?


Many thanks

Martyn
Access 2000, Windows 2003 server over Citrix MF
 
J

Jerry Whittle

SELECT TARGETS.[User Name],
Count(TARGETS.Bad) AS CreatedTargets
Sum(Abs(TARGETS.Bad)) AS BadTargets
FROM TARGETS
GROUP BY TARGETS.[User Name]
ORDER BY Sum(Abs(TARGETS.Bad)) DESC;

I'm assuming a Yes/No field and no null values.
 
W

WembleyBear

Thanks very much Jerry

That worked a treat!


Martyn

Jerry Whittle said:
SELECT TARGETS.[User Name],
Count(TARGETS.Bad) AS CreatedTargets
Sum(Abs(TARGETS.Bad)) AS BadTargets
FROM TARGETS
GROUP BY TARGETS.[User Name]
ORDER BY Sum(Abs(TARGETS.Bad)) DESC;

I'm assuming a Yes/No field and no null values.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

WembleyBear said:
Hi

I have a query that is based on a table called TARGETS which returns the
number of targets in the table that are marked as "bad", and then grouped by
user. The code for this query is:

SELECT TARGETS.[User Name], Count(TARGETS.Bad) AS CountOfBad
FROM TARGETS
GROUP BY TARGETS.[User Name]
HAVING (((Count(TARGETS.Bad))=True))
ORDER BY Count(TARGETS.Bad) DESC;

What I want to do in addition to the count of bad target records created by
user name, is to show the total number of records created by each user, so
that the result is something like:

Created Bad
Mary Jones 17 4
Bob Smith 12 3
etc

What is the best way to do this?

Many thanks

Martyn
Access 2000, Windows 2003 server over Citrix MF
 

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