Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old February 15th, 2006, 05:15 PM
cwhite
Guest
 
Posts: n/a
Default query for two values

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




  #2  
Old February 15th, 2006, 07:45 PM
GH
Guest
 
Posts: n/a
Default Re: query for two values

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

  #3  
Old February 16th, 2006, 04:15 PM
cwhite
Guest
 
Posts: n/a
Default Re: query for two values

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.