Server version: 5.0.24
This query is working OK for me. I'm using FROM_DAYS() to avoid errors
due to leap years.
SELECT extract(YEAR FROM from_days(datediff(curdate(), dateofbirth))) AS
age, SUM(extract(YEAR FROM from_days(datediff(curdate(), birth_date
AS total_age FROM user_inf
> > But you can't get a group by from an alias.
>
> That surprises me. I tried putting the calculation of age in a
> subquery but that didn't work, either. And I've never quite
> figured out how to create a temporary table for intermediate
> results. There has _got_ to be a way to do this, e
Nelson:
I have double checked my last post, and the following works:
"
SELECT
DISTINCT(FLOOR((datediff(curdate(), dateofbirth)/365))) as age,
COUNT(FLOOR((datediff(curdate(), dateofbirth)/365))) AS total_age
from myTable
group by age
"
Tell us if it worked for you.
Regards,
Alvaro
On 9/17/0
> If your dateOfBirth is a date field,
It is.
> you can do this:
>
> select
> (substring(curdate(),1,4)-substring(dateofbirth,1,4))-
> (substr(curdate(),5) as age
> from myTable;
Thanks. That's a little more accurate (thought that doesn't quite
matter in my case).
> But you can't get a
You could try something like this:
SELECT
DISTINCT(round(datediff(curdate(), dateofbirth)/365)) as age,
COUNT(round(datediff(curdate(), dateofbirth)/365)) AS total_age
from myTable
group by age
Not sure, but could work.
Regards,
Alvaro
João Cândido de Souza Neto escribió:
> If your dateOfBirt
If your dateOfBirth is a date field, you can do this:
select
(substring(curdate(),1,4)-substring(dateofbirth,1,4))-(substr(curdate(),5) escreveu na mensagem
news:[EMAIL PROTECTED]
> I'm working on MySQL v5.0 and I have a table with dateOfBirth and I want
> a histogram of ages at a point in time.
I'm working on MySQL v5.0 and I have a table with dateOfBirth and I want
a histogram of ages at a point in time. I tried something like:
select round(datediff(curdate(), dateofbirth)/365) as age, count(age)
from myTable group by age;
but MySQL Query Browser says:
Unknown column 'age' in