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/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> 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)<substr(dateofbirth,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 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, even an awkward way.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


Reply via email to