How to calculate age from date of birth and group each member into age range in sql

saint

I have an sql table that stores people's details i.e id, name, DoB, registration_date and address. I would like to calculate the age of each individual and then group them into these ranges: 20-30, 31-50, 51 & over.

I know i can get the age by doing: (https://stackoverflow.com/a/1572257/3045800)

SELECT FLOOR((CAST (GetDate() AS INTEGER) - CAST(Date_of_birth AS INTEGER)) / 365.25) AS Age

I just need to figure out how to group all people into thier respective range.

Thanks for the help

Bohemian

Use a case to produce the age group description:

select *,
  case
    when datediff(now(), date_of_birth) / 365.25 > 50 then '51 & over'
    when datediff(now(), date_of_birth) / 365.25 > 30 then '31 - 50'
    when datediff(now(), date_of_birth) / 365.25 > 19 then '20 - 30'
    else 'under 20'
  end as age_group
from person

Note the simpler way to calculate age.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to calculate age from date of birth and group each member into age range in sql

From Dev

Calculate age from birth date

From Dev

How to calculate age (in years) based on Date of Birth in SQL

From Dev

How to calculate age (in years) based on Date of Birth in SQL

From Dev

Calculate age with decimals from date of birth

From Dev

SQL group customers by age given date of birth

From Dev

how to add Check constraints on mysql that age calculate from Date of birth field and validate that age is greater than 18

From Java

Calculate age based on date of birth

From Dev

Calculate the age using the date of birth

From Dev

Calculate age based on date of birth

From Dev

Calculate the age using the date of birth

From Dev

Javascript to calculate a fictional date of birth from todays date and fixed age

From Dev

SQL Calculate the age .use DatePart on DATE()) minus year of birth

From Dev

Validating Age from the Date of Birth

From Dev

Calculate age from birth date using NSDateComponents in Swift

From Dev

SQL query to group by age range from date created

From Dev

How can I calculate age in Java accurately given Date of birth

From Dev

How to Calculate Age given date of birth using NHibernate QueryOver

From Dev

Date of birth to Age range using PHP

From Dev

SQL Server calculating age from varchar date of birth

From Dev

SQL. Convert age to date of birth

From Dev

change a column from birth date to age in r

From Dev

MySQL Age from Date of Birth (ignore nulls)

From Dev

Calucate age from birth date in mysql

From Dev

Finding date of birth from age in java

From Dev

Basic age validation from date of birth in PHP

From Dev

Finding date of birth from age in java

From Dev

Calculate age based on date of birth for dd/mm/yyyy date format

From Dev

SAS calculate age based on year of birth and a complete end date

Related Related

  1. 1

    How to calculate age from date of birth and group each member into age range in sql

  2. 2

    Calculate age from birth date

  3. 3

    How to calculate age (in years) based on Date of Birth in SQL

  4. 4

    How to calculate age (in years) based on Date of Birth in SQL

  5. 5

    Calculate age with decimals from date of birth

  6. 6

    SQL group customers by age given date of birth

  7. 7

    how to add Check constraints on mysql that age calculate from Date of birth field and validate that age is greater than 18

  8. 8

    Calculate age based on date of birth

  9. 9

    Calculate the age using the date of birth

  10. 10

    Calculate age based on date of birth

  11. 11

    Calculate the age using the date of birth

  12. 12

    Javascript to calculate a fictional date of birth from todays date and fixed age

  13. 13

    SQL Calculate the age .use DatePart on DATE()) minus year of birth

  14. 14

    Validating Age from the Date of Birth

  15. 15

    Calculate age from birth date using NSDateComponents in Swift

  16. 16

    SQL query to group by age range from date created

  17. 17

    How can I calculate age in Java accurately given Date of birth

  18. 18

    How to Calculate Age given date of birth using NHibernate QueryOver

  19. 19

    Date of birth to Age range using PHP

  20. 20

    SQL Server calculating age from varchar date of birth

  21. 21

    SQL. Convert age to date of birth

  22. 22

    change a column from birth date to age in r

  23. 23

    MySQL Age from Date of Birth (ignore nulls)

  24. 24

    Calucate age from birth date in mysql

  25. 25

    Finding date of birth from age in java

  26. 26

    Basic age validation from date of birth in PHP

  27. 27

    Finding date of birth from age in java

  28. 28

    Calculate age based on date of birth for dd/mm/yyyy date format

  29. 29

    SAS calculate age based on year of birth and a complete end date

HotTag

Archive