List:General Discussion« Previous MessageNext Message »
From:Alvaro Cobo Date:September 18 2006 5:03am
Subject:Re: Query to get count of ages
View as plain text  
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, cnelson@stripped <cnelson@stripped> 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/mysql?unsub=1
>
>

Thread
Query to get count of agescnelson16 Sep
  • Re: Query to get count of agesjoao16 Sep
    • Re: Query to get count of agesAlvaro Cobo16 Sep
    • Re: Query to get count of agescnelson18 Sep
      • Re: Query to get count of agesAlvaro Cobo18 Sep
      • Re: Query to get count of agescnelson19 Sep
  • Re: Query to get count of agesAnders Lundgren19 Sep