|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Age AverageI have to calculate the average age in a group.
What is the best way to calculate the average age where I have the individual's birth date??? Thanks in advance! I would use
select datediff(mm, yourDOB, getdate())/12.0 Perayu Show quote "wnfisba" <wnfi***@discussions.microsoft.com> wrote in message news:F3FCEC3B-D90D-42C5-B42D-179206660285@microsoft.com... >I have to calculate the average age in a group. > > What is the best way to calculate the average age where I have the > individual's birth date??? > > Thanks in advance! SELECT AVG(DATEDIFF(DAY,birth_date,CURRENT_TIMESTAMP))/365.25
FROM YourTable GROUP BY ... -- David Portas SQL Server MVP -- wnfisba wrote:
> I have to calculate the average age in a group. More information please...> > What is the best way to calculate the average age where I have the > individual's birth date??? > > Thanks in advance! Post your table DDL and more detailed specs of what you're trying to accomplish. SQL has an AVG() function to calculate averages based on a set of data. As an alternative to getting the average age, you could get the average
birthdate. That could be more useful in some circumstances. Show quote "wnfisba" <wnfi***@discussions.microsoft.com> wrote in message news:F3FCEC3B-D90D-42C5-B42D-179206660285@microsoft.com... >I have to calculate the average age in a group. > > What is the best way to calculate the average age where I have the > individual's birth date??? > > Thanks in advance! Just be sure it's birthdate, not birth(month/day). I can see the headline:
"Average American born in early July, study shows." ;) Steve Kass Drew University Paul Pedersen wrote: Show quote >As an alternative to getting the average age, you could get the average >birthdate. That could be more useful in some circumstances. > > >"wnfisba" <wnfi***@discussions.microsoft.com> wrote in message >news:F3FCEC3B-D90D-42C5-B42D-179206660285@microsoft.com... > > >>I have to calculate the average age in a group. >> >>What is the best way to calculate the average age where I have the >>individual's birth date??? >> >>Thanks in advance! >> >> > > > > Ha ha! So I'm average after all.
Show quote "Steve Kass" <sk***@drew.edu> wrote in message news:OcEysRNsFHA.1252@TK2MSFTNGP09.phx.gbl... > Just be sure it's birthdate, not birth(month/day). I can see the > headline: > "Average American born in early July, study shows." ;) > > Steve Kass > Drew University > > Paul Pedersen wrote: > >>As an alternative to getting the average age, you could get the average >>birthdate. That could be more useful in some circumstances. >> >> >>"wnfisba" <wnfi***@discussions.microsoft.com> wrote in message >>news:F3FCEC3B-D90D-42C5-B42D-179206660285@microsoft.com... >> >>>I have to calculate the average age in a group. >>> >>>What is the best way to calculate the average age where I have the >>>individual's birth date??? >>> >>>Thanks in advance! >> >> >> |
|||||||||||||||||||||||