query for two values

query for two values

am 15.02.2006 18:07:18 von C White

I have a query that will count everything by location:

SELECT DISTINCTROW [Tracking].[Location], Count([Tracking].[ID]) AS
Total


it will show me

location total
a 10
b 15
c 7


but I would like to break it down further, the records also store a
person's name (the field is called name), so that I can get it to show
me

location name total
a tom 3
a dick 4
a harry 3
b tom 5
b dick 6
b harry 4
c tom 1
c dick 2
c harry 4

i've been looking at this for a couple of hours now, and i can't seem
to find the answer anywhere, anytime i try to write something it gives
me the following error

"you tried to execute a query that does not include the specified
expression"

which obviously means i have no idea what i am doing

how do i write the query to display the breakdown by location and name?

thanks

Re: query for two values

am 15.02.2006 20:38:15 von GH

If I understand the error (it looks incomplete), you need a GROUP BY
clause added to your query that tells it to group on name within
location. It would look like:

SELECT DISTINCTROW [Tracking].[Location],
[YOURTABLENAME].[YOURNAMEFIELD] as 'Name', Count([Tracking].[ID]) AS
Total
FROM --- list the tables, query, or whatever here with any needed join
condition
GROUP BY [Tracking].[Location], [YOURTABLENAME].[YOURNAMEFIELD]

I did not assume that your table and field for the names are "Tracking"
and "Name", but you can easily substitute these for the bracketed items
in the query above.

- GH

Re: query for two values

am 16.02.2006 17:05:51 von C White

it worked, I kept trying to join them by doing

GROUP BY [Tracking].[Location] AND [YOURTABLENAME].[YOURNAMEFIELD]

now I can see that I needed to use a comma "," instead of "AND", its
obvious now that I either need to get a clue or find a good
book/website for my reference

thanks