PC Review


Reply
Thread Tools Rate Thread

Count of a grouped by field

 
 
JustinP
Guest
Posts: n/a
 
      6th Sep 2006
I need to do a count of a grouped by field. Is this possible?

i.e. Table:

Property Owner
1 Bob
2 Alan
3 Alan
4 Bob
5 Bob
6 Bob

Group By Owner:
Alan
Bob

Count of Group By:
2

How do I write the count of group by in SQL?

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      6th Sep 2006
"JustinP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> I need to do a count of a grouped by field. Is this possible?
>
> i.e. Table:
>
> Property Owner
> 1 Bob
> 2 Alan
> 3 Alan
> 4 Bob
> 5 Bob
> 6 Bob
>
> Group By Owner:
> Alan
> Bob
>
> Count of Group By:
> 2
>
> How do I write the count of group by in SQL?


As I understand it, you want what in some versions of SQL is available
as a COUNT DISTINCT operation. Access (Jet) SQL doesn't support that,
as far as I know, but you could write this:

SELECT Count(*) FROM
(SELECT DISTINCT Owner FROM Properties);

where "Properties" is the name of the table.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?V2F5bmUtSS1N?=
Guest
Posts: n/a
 
      6th Sep 2006
Hi Justin

It would be simpler to use a Totals Query.


--
Wayne
Manchester, England.
Enjoy whatever it is you do


"JustinP" wrote:

> I need to do a count of a grouped by field. Is this possible?
>
> i.e. Table:
>
> Property Owner
> 1 Bob
> 2 Alan
> 3 Alan
> 4 Bob
> 5 Bob
> 6 Bob
>
> Group By Owner:
> Alan
> Bob
>
> Count of Group By:
> 2
>
> How do I write the count of group by in SQL?
>
>

 
Reply With Quote
 
JustinP
Guest
Posts: n/a
 
      6th Sep 2006
I already have other queries within this queries such as:

SELECT Count(*) AS TotalProperties,
Sum(IIf(MasterTable.SECTION_NAME="BCab",1,0)) AS CountOfBundCab,
FROM MasterTable;

Is it possible to include the solution you suggested in that as well?


> As I understand it, you want what in some versions of SQL is available
> as a COUNT DISTINCT operation. Access (Jet) SQL doesn't support that,
> as far as I know, but you could write this:
>
> SELECT Count(*) FROM
> (SELECT DISTINCT Owner FROM Properties);
>
> where "Properties" is the name of the table.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)


 
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
Count unique field1 combined with count field2, both grouped andungrouped john.mctigue@health.wa.gov.au Microsoft Access Queries 3 19th Dec 2008 03:52 AM
Need to know grouped count. Madiya Microsoft Excel Programming 2 31st Oct 2008 10:20 AM
Grouped Multiple Count Query Matt Microsoft Access Queries 3 28th Apr 2005 03:37 AM
Count the grouped names for a total =?Utf-8?B?SmVubmlmZXI=?= Microsoft Access Reports 3 23rd Apr 2004 05:01 AM
cell count of 'grouped' cells Andy Microsoft Excel Misc 1 27th Nov 2003 01:29 PM


Features
 

Advertising
 

Newsgroups
 


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