vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Average Age (https://vborg.vbsupport.ru/showthread.php?t=33554)

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:
Code:

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:
Code:

SELECT [high]ROUND([/high]YEAR(NOW())-AVG(YEAR(birthday))[high],2)[/high] 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:
Code:

SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE birthday != 0000-00-00
That 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

Code:

SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE YEAR(birthday) <> 0
I 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
Code:

SELECT YEAR(NOW())-AVG(YEAR(birthday)) AS avgage FROM user WHERE YEAR(birthday) <> 0
I 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/showthrea...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:

PHP Code:

// 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?


All times are GMT. The time now is 03:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02092 seconds
  • Memory Usage 1,752KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (24)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete