Re: Query to get count of ages

2006-09-19 Thread Anders Lundgren
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

Re: Query to get count of ages

2006-09-19 Thread cnelson
> > 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

Re: Query to get count of ages

2006-09-17 Thread Alvaro Cobo
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

Re: Query to get count of ages

2006-09-17 Thread cnelson
> 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

Re: Query to get count of ages

2006-09-15 Thread Alvaro Cobo
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

Re: Query to get count of ages

2006-09-15 Thread Jo�o C�ndido de Souza Neto
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.

Query to get count of ages

2006-09-15 Thread cnelson
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