Re: Query for Averageing

From: MGFoster (me_at_privacy.com)
Date: 04/06/04


Date: Tue, 06 Apr 2004 01:05:36 GMT

RobinF wrote:

> Can someone help me set up a query where the totals of
> the fields are added up and then divided by the number of
> fields to obtain an average.
>
> However, if there is no number in a field then the
> average is to not include that field in the averge.
>
> e.g. Field1 Field2 Field3 Field4 Avg
> 10 8 12 25 13.75 = Total / 4
>
> 10 25 8.75 = Total / 4
>
> What I want Is not Total / 4 but Total / no of field with
> numbers So I Need Total / 2 becouse only 2 fields have
> numbers.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If this is a table it is incorrectly designed. If the table was
designed correctly you could use the SQL function Avg() to get the
correct average. E.g.:

Table Design:
   ID The record id - no nulls
   NumberField Your number field - can be null

Get the average:

SELECT ID, Avg(NumberField)
FROM TableName
GROUP BY ID

Using your data as the example you'd get the resultset of:

ID NumberFieldAvg Raw Data
------- -------------- --------
1 13.75 (10+8+12+25)/4
2 17.5 (10+25)/2

-- 
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQHICLIechKqOuFEgEQL5jACgschsevDbfN1YFODc/uOZOIrVnj8AoJ3L
ocd1sKukYEM/BE9bYarrYy5t
=lTky
-----END PGP SIGNATURE-----


Relevant Pages

  • Re: Query for Averageing
    ... >RobinF wrote: ... >> Can someone help me set up a query where the totals of ... >Table Design: ...
    (microsoft.public.access.queries)
  • Re: Top Secret Crypto 3.70
    ... You can solve it the way pgp 2 handled it - use user keystrokes ... untested design is insecure and unwise. ... I've seen very few ciphers that I would call simple and elegant. ...
    (sci.crypt)
  • Re: Top Secret Crypto 3.70
    ... You can solve it the way pgp 2 handled it - use user keystrokes ... untested design is insecure and unwise. ... I've seen very few ciphers that I would call simple and elegant. ...
    (alt.computer.security)
  • Re: Top Secret Crypto 3.70
    ... You can solve it the way pgp 2 handled it - use user keystrokes ... untested design is insecure and unwise. ... I've seen very few ciphers that I would call simple and elegant. ...
    (linux.redhat)
  • Re: PGP and sendmail
    ... handle automatic encryption and decryption of e-mail through sendmail? ... I suppose you could design a system that automatically handles this ... for something that works with PGP for users to use with their sendmail ... Scheme Programming is subtle; subtlety can be hard. ...
    (comp.mail.sendmail)