PC Review


Reply
Thread Tools Rate Thread

Case of the curious query ; count the codes

 
 
barret bondon
Guest
Posts: n/a
 
      28th Feb 2011
Trying to get a count of the number of records for each code; that is: 90000
records with a code field; some code "a" records have 1000 records and some
code "b" records have 20000 records; I'd like to know !
In other words; ther are perhaps 20 codes; there is a "code" field with
these repeating codes; I'd like a count of how many records contain code "c"
and how many have code "d", etc.
I've tried this , and many many other variations !

SELECT contacts.code Count(contacts.code) AS CountOfItemName
FROM
(SELECT DISTINCT code ) As q
GROUP BY code;


 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      28th Feb 2011
On Mon, 28 Feb 2011 12:02:49 -0500, "barret bondon" <(E-Mail Removed)>
wrote:

>Trying to get a count of the number of records for each code; that is: 90000
>records with a code field; some code "a" records have 1000 records and some
>code "b" records have 20000 records; I'd like to know !
>In other words; ther are perhaps 20 codes; there is a "code" field with
>these repeating codes; I'd like a count of how many records contain code "c"
>and how many have code "d", etc.
>I've tried this , and many many other variations !
>
>SELECT contacts.code Count(contacts.code) AS CountOfItemName
>FROM
>(SELECT DISTINCT code ) As q
>GROUP BY code;
>


Sounds like you don't really want to count *codes*; you want to count *records
for each code*. If that's the case lose the subquery:

SELECT code, Count(*) AS CountOfCodes
FROM yourtablename
GROUP BY code;

As written your query makes no sense, since neither the query nor the subquery
references a table.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      28th Feb 2011
barret bondon wrote:
> Trying to get a count of the number of records for each code; that
> is: 90000 records with a code field; some code "a" records have 1000
> records and some code "b" records have 20000 records; I'd like to
> know ! In other words; ther are perhaps 20 codes; there is a "code" field
> with these repeating codes; I'd like a count of how many records
> contain code "c" and how many have code "d", etc.
> I've tried this , and many many other variations !
>
> SELECT contacts.code Count(contacts.code) AS CountOfItemName
> FROM
> (SELECT DISTINCT code ) As q
> GROUP BY code;

You're overcomplicating it. This should do what you want:

SELECT code, count(*) As CountPerCode
FROM Contacts
GROUP BY code


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Count(Case()) SQL Server Query to Access meyvn77@yahoo.com Microsoft Access Queries 3 17th Nov 2005 11:06 PM
Re: Query to look up a number of zip codes or area codes for bulkmail MGFoster Microsoft Access Queries 5 16th Apr 2005 04:38 AM
Boot Driver Agony, a Curious Case Frank Haber Windows XP Hardware 2 11th Aug 2004 03:26 AM
curious dvd format query difazio Windows XP MovieMaker 2 11th May 2004 08:59 PM
case codes jn Microsoft Access Security 1 30th Sep 2003 08:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 AM.