A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Counting Records in A Group



 
 
Thread Tools Display Modes
  #1  
Old January 13th, 2010, 11:18 PM posted to microsoft.public.access
Robin
external usenet poster
 
Posts: 481
Default Counting Records in A Group

I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


  #2  
Old January 14th, 2010, 12:30 AM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Counting Records in A Group

Try this --
SELECT [People ID], [Course Name], Count([Email ID]) as Email_Count
FROM [Publish Table]
GROUP BY [People ID], [Course Name];

--
Build a little, test a little.


"Robin" wrote:

I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


  #3  
Old January 14th, 2010, 12:36 AM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Counting Records in A Group

Try this:

SELECT [Course Name], COUNT(*) AS StudentCount
FROM (SELECT DISTINCT [Course Name], [People ID]
FROM [Publish Table])
GROUP BY [Course Name];

The subquery returns the distinct values of Course name and StudentID, i.e
one row per course per student. By grouping the result of the subquery by
Course Name and counting the rows the number of students who have sent in one
or more emails per course is returned.

If you save the query and then reopen it in SQL view you'll fund that Access
has given the subquery an arbitrary alias. You can change the alias to
something more intelligible if you wish.

Ken Sheridan
Stafford, England

Robin wrote:
I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access/201001/1

  #4  
Old January 14th, 2010, 01:11 AM posted to microsoft.public.access
kenista
external usenet poster
 
Posts: 17
Default Counting Records in A Group

This has helped me out, but is there a way to also count the fields that have
no entries?

For example:

Problem Number of responses
enter key doesn't work 2
can't find help 0
what is a database 5

"KARL DEWEY" wrote:

Try this --
SELECT [People ID], [Course Name], Count([Email ID]) as Email_Count
FROM [Publish Table]
GROUP BY [People ID], [Course Name];

--
Build a little, test a little.


"Robin" wrote:

I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


  #5  
Old January 14th, 2010, 04:33 AM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Counting Records in A Group

I can only work with information you provide.

What field contains 'Problem'?

--
Build a little, test a little.


"kenista" wrote:

This has helped me out, but is there a way to also count the fields that have
no entries?

For example:

Problem Number of responses
enter key doesn't work 2
can't find help 0
what is a database 5

"KARL DEWEY" wrote:

Try this --
SELECT [People ID], [Course Name], Count([Email ID]) as Email_Count
FROM [Publish Table]
GROUP BY [People ID], [Course Name];

--
Build a little, test a little.


"Robin" wrote:

I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


  #6  
Old January 14th, 2010, 12:22 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Counting Records in A Group

You'll need two tables, one for Problems the other for Responses, related on
Problem. Then use a LEFT OUTER JOIN in the query:

SELECT Problems.Problem,
COUNT(Responses.Problem) AS [Number of Responses]
FROM Problems LEFT JOIN Responses
ON Problems.Problem = Responses.Problem
GROUP BY Problems.Problem;

Ken Sheridan
Stafford, England

kenista wrote:
This has helped me out, but is there a way to also count the fields that have
no entries?

For example:

Problem Number of responses
enter key doesn't work 2
can't find help 0
what is a database 5

Try this --
SELECT [People ID], [Course Name], Count([Email ID]) as Email_Count

[quoted text clipped - 21 lines]

Help!


--
Message posted via http://www.accessmonster.com

  #7  
Old January 15th, 2010, 12:51 AM posted to microsoft.public.access
kenista
external usenet poster
 
Posts: 17
Default Counting Records in A Group

My code is as follows:

SELECT Problem, Count(Problem) AS Problem_Count
FROM Queries_Table
GROUP BY Problem;

I want to be able to show (count) the fields that don't have any entries.

"KARL DEWEY" wrote:

I can only work with information you provide.

What field contains 'Problem'?

--
Build a little, test a little.


"kenista" wrote:

This has helped me out, but is there a way to also count the fields that have
no entries?

For example:

Problem Number of responses
enter key doesn't work 2
can't find help 0
what is a database 5

"KARL DEWEY" wrote:

Try this --
SELECT [People ID], [Course Name], Count([Email ID]) as Email_Count
FROM [Publish Table]
GROUP BY [People ID], [Course Name];

--
Build a little, test a little.


"Robin" wrote:

I have a table that has one row per email sent in by a student, organized by
the class they attend. I would like to count the number of students that have
sent in emails per class. I can't seem to get my brain around this, and what
I get every time is either the number of emails per class or the number of
emails per student.

My Table: [Publish Table]
Columns: [Course Name] = name of class,[People ID]=identifier for the
student,[Email ID]=identifier for the email in a different table

I've tried this query - gives me a row per student and the number of emails
for the student. Tried putting in DISTINCT and DISTINCTROW to no avail.

SELECT [Course Name], Count([People ID]) as CountPeople
FROM [Publish Table]
GROUP BY [Course Name],[People ID]

Instead I'd like to know how many students sent emails.

Help!


  #8  
Old January 15th, 2010, 03:11 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Counting Records in A Group

On Thu, 14 Jan 2010 16:51:01 -0800, kenista
wrote:

My code is as follows:

SELECT Problem, Count(Problem) AS Problem_Count
FROM Queries_Table
GROUP BY Problem;

I want to be able to show (count) the fields that don't have any entries.


You will need (and, hopefully, already have) another table containing all the
valid values of Problem. Let's call it Problems. A query

SELECT P.Problem, Count(*) AS Problem_Count
FROM Problem AS P LEFT JOIN Queries_Table AS Q
ON P.Problem = Q.Problem;

The ahem problem is that if there is no record in Queries_Table then Access
can't count what isn't there! I'm pretty sure there are no records where the
Problem is "Insufficient Energy in the Freem drives for liftoff"... but I
doubt that you want to see that with a 0 by it!
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.