PC Review


Reply
Thread Tools Rate Thread

Counting records in a table

 
 
Jeffrey Marks
Guest
Posts: n/a
 
      12th Jul 2010

I have a table that has 5 different test scores (reading, writing,
math, SS, and science) per records in the table. The student may take
these tests multiple times (until passed). So a test score may have a
score (1-600) in the field or it may be null.

I'd like to total the number of time each student takes a given test
(e.g. how many times did he/she take the math test). When I'm done I
also want to see how many tests were taken, but if I have the total
count of how many times each test was taken, I can easily sum those to
get the overall total.

Is the best way to approach this an IIF statement, stating that if the
score is not one add 1 to the total? Or is there a more efficient way
to code this?

Thanks as always

Jeff
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      12th Jul 2010
On Mon, 12 Jul 2010 13:28:18 -0700 (PDT), Jeffrey Marks <(E-Mail Removed)>
wrote:

>
>I have a table that has 5 different test scores (reading, writing,
>math, SS, and science) per records in the table. The student may take
>these tests multiple times (until passed). So a test score may have a
>score (1-600) in the field or it may be null.
>
>I'd like to total the number of time each student takes a given test
>(e.g. how many times did he/she take the math test). When I'm done I
>also want to see how many tests were taken, but if I have the total
>count of how many times each test was taken, I can easily sum those to
>get the overall total.
>
>Is the best way to approach this an IIF statement, stating that if the
>score is not one add 1 to the total? Or is there a more efficient way
>to code this?
>
>Thanks as always
>
>Jeff


If you have one field for each test, your table isn't properly designed! A
better structure would have one record per test result - fields for the
student ID, the test ID, perhaps the date taken and the score.

With your current design how do you handle the case where a student passes
reading on the first try, but has to take math three times? Do you have two
records with null Reading scores?

If you want to count the number of non-NULL results for each test, you can use
a totals query:

SELECT StudentID, Sum(IIF(IsNull([Reading]), 0, 1)) AS CountOfReading,
Sum(IIF(IsNull([Writing]), 0, 1)) AS CountOfWriting, <etc>

Am I understanding the table structure correctly? If not could you post some
sample data?
--

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
 
Jeff Boyce
Guest
Posts: n/a
 
      12th Jul 2010
As John points out, the likely table structure (one colum per test) is ... a
spreadsheet! In a well-normalized relational database, the table would be
designed as John offers.

So what, you ask? So MS Access is designed to work best with
well-normalized data. If you try to feed it 'sheet data, both you and
Access have to work overtime to come up with work arounds.

It all starts with the data!

Regareds

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Jeffrey Marks" <(E-Mail Removed)> wrote in message
news:ee4974dc-c4b5-4123-a111-(E-Mail Removed)...
>
> I have a table that has 5 different test scores (reading, writing,
> math, SS, and science) per records in the table. The student may take
> these tests multiple times (until passed). So a test score may have a
> score (1-600) in the field or it may be null.
>
> I'd like to total the number of time each student takes a given test
> (e.g. how many times did he/she take the math test). When I'm done I
> also want to see how many tests were taken, but if I have the total
> count of how many times each test was taken, I can easily sum those to
> get the overall total.
>
> Is the best way to approach this an IIF statement, stating that if the
> score is not one add 1 to the total? Or is there a more efficient way
> to code this?
>
> Thanks as always
>
> Jeff



 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      13th Jul 2010
All you need to do is COUNT the scores for each field. Count counts the
presence of a value. Nulls are NOT counted.

In the query design view
== Add your table
== Add the 5 fields
== Select View: Totals from the menu (2003 and earlier)
== Change Group by to Count under the 5 fields

SQL view would look like

SELECT Count(Reading) as RCount
, Count(Writing) as WCount
, Count(Math) as MCount
, Count(SS) as SSCount
, Count(Science) as SCount
FROM [YourTableName]



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Jeffrey Marks wrote:
> I have a table that has 5 different test scores (reading, writing,
> math, SS, and science) per records in the table. The student may take
> these tests multiple times (until passed). So a test score may have a
> score (1-600) in the field or it may be null.
>
> I'd like to total the number of time each student takes a given test
> (e.g. how many times did he/she take the math test). When I'm done I
> also want to see how many tests were taken, but if I have the total
> count of how many times each test was taken, I can easily sum those to
> get the overall total.
>
> Is the best way to approach this an IIF statement, stating that if the
> score is not one add 1 to the total? Or is there a more efficient way
> to code this?
>
> Thanks as always
>
> Jeff

 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      13th Jul 2010
John Spencer <(E-Mail Removed)> wrote in
news:i1hkgb$dq4$(E-Mail Removed):

> All you need to do is COUNT the scores for each field. Count
> counts the presence of a value. Nulls are NOT counted.


Does COUNT() use distinct values, or all of them?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      15th Jul 2010
If you want a count of distinct values then you can use Allen Browne's ECount
function or you can run a query to get distinct values and then use that to
get the count.

Count in Access Jet/ACE counts the presence of a value. So if ten records are
returned and they all have the same value in the field you are counting the
count is ten.

See
ECount() - an extended DCount()
at:
http://allenbrowne.com/ser-66.html

SQL server Transact SQL has the ability to do a distinct count. As I recall
the syntax is
Count(Distinct Field) as CountUniqueValues


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

David W. Fenton wrote:
> John Spencer <(E-Mail Removed)> wrote in
> news:i1hkgb$dq4$(E-Mail Removed):
>
>> All you need to do is COUNT the scores for each field. Count
>> counts the presence of a value. Nulls are NOT counted.

>
> Does COUNT() use distinct values, or all of them?
>

 
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
Re: Counting Yes/No responses from multiple records in a table Jeff Boyce Microsoft Access Queries 4 15th Jan 2010 04:16 PM
Re: Counting Yes/No responses from multiple records in a table John Spencer Microsoft Access Queries 0 7th Oct 2009 07:37 PM
Listbox for counting number of records in table =?Utf-8?B?UGV0ZXIgQWRlbWE=?= Microsoft Access VBA Modules 5 18th Feb 2005 08:17 AM
Counting number of records in a table Rosemary Microsoft Access VBA Modules 2 18th Sep 2004 02:28 PM
Counting records within a group of a table and updating the table Di Microsoft Access Queries 4 27th Jul 2004 10:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 PM.