PDA

View Full Version : Average Age


pgowder
12-27-2001, 05:36 PM
I'd like to compute the average age of my users for statistical information.

Any ideas on how to write this query?

Admin
12-27-2001, 06:57 PM
The query:
SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user;
You might want to round() it later, or you can do it directly in the query using MySQL's ROUND() function, for example:
SELECT ROUND(YEAR(NOW())-AVG(YEAR(birthday)),2) AS avgage FROM user;
will round it to 2 decimal points.

pgowder
12-27-2001, 07:48 PM
How can I eliminate the ones that didn't input a year?

Psychdrone
12-27-2001, 08:35 PM
wow sweet!

Where would I put this code and where would I recieve the results!

FWC
12-27-2001, 08:48 PM
[QUOTE]Originally posted by pgowder
How can I eliminate the ones that didn't input a year?

pgowder
12-27-2001, 11:36 PM
Here is what I tried:

[QUOTE]SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage
WHERE birthday != 0000-00-00 FROM user

FWC
12-28-2001, 12:28 AM
After FROM user:

SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE birthday != 0000-00-00That doesn't error, but I got a strange result. My average user is 216 years old. :)

I think it may be because we are excluding the the unset year cells but the total rows aren't changing when the average is calculated.

Psychdrone
12-28-2001, 02:20 AM
could someone answer me please!

Thanks!

Freddie Bingham
12-28-2001, 02:23 AM
SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE YEAR(birthday) <> 0I wasn't aware of the YEAR() function, I will have to check that out.

FWC
12-28-2001, 02:58 AM
[QUOTE]Originally posted by freddie
SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE YEAR(birthday) <> 0I wasn't aware of the YEAR() function, I will have to check that out.

pgowder
12-28-2001, 11:19 AM
That works, thanks guys!

Admin
12-28-2001, 11:22 AM
Don't I rock as well? :(

Freddie Bingham
12-28-2001, 01:23 PM
NO, only I do!

Lesane
12-28-2001, 03:23 PM
hmmm......this is my result: Array :confused:

Admin
12-28-2001, 04:27 PM
[QUOTE]Originally posted by freddie
NO, only I do!

djr
12-28-2001, 04:49 PM
whoa, my users are old :-) (32.3151 average)

- djr

oops, accidentaly clicked 'new thread' instead of 'new reply'.
Please move this to https://vborg.vbsupport.ru/showthread.php?s=&threadid=33554

thanks and sorry

- djr

Lesane
12-28-2001, 04:54 PM
Aight, Thanks Firefly

FWC
12-28-2001, 04:54 PM
[QUOTE]Originally posted by FireFly
Don't I rock as well? :(

Freddie Bingham
12-28-2001, 05:08 PM
[QUOTE]Originally posted by FWC
Yeah, but I tell you and Bira "you rock" all the time. :)

I don't get as many chances with Freddie. :)

FWC
12-28-2001, 05:15 PM
[QUOTE]Originally posted by freddie
No need. I will get enough of that when v3 is released ;) Then that will quickly be followed by "you suck, why did you change that???".

Psychdrone
12-29-2001, 02:08 AM
you all rock! :rolleyes:

Could someone help me out with my question please!

Lesane
12-29-2001, 07:13 AM
Psychdrone, add this in your index.php:

// average age
$result=$DB_site->query_first("SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE YEAR(birthday) <> 0");
$age=$result['avgage'];

And put $age in your forumhome template

merk
12-31-2001, 04:35 AM
[QUOTE]Originally posted by freddie
No need. I will get enough of that when v3 is released ;) Then that will quickly be followed by "you suck, why did you change that???".

DannyITR
03-29-2004, 02:37 PM
I get Null as an answer. Does this work for VB gold?