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 dateOfBirth is a date field, you can do this: > > select > (substring(curdate(),1,4)-substring(dateofbirth,1,4))-(substr(curdate(),5)<substr(dateofbirth,5)) > > as age > from myTable; > > But you can't get a group by from an alias. > > Hope help. > > <[EMAIL PROTECTED]> 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 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 'field list' 1054 >> >> What am I doing wrong? How can I count ages? > > > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]