Answer the question
In order to leave comments, you need to log in
SQL query to display age range given only date of birth?
I ran into a problem, I need to display the ID, Status, Title of the work and the range of the age category,
I can’t display it because the database contains only the date of birth of a person from 03/19/1958 to 2005, I can’t figure out how to make a BETWEEN request so that it automatically does range in age that is sorted from 25 let's say to 50 years old.
SELECT LoginID,MaritalStatus,BirthDate,JobTitle
FROM HumanResources.Employee where MaritalStatus='S' and JobTitle like '%Specialist' and BirthDate Between 25 and 50 (does not work, I understand that you need to specify the date of birth in this way), point out the error, thank.
Answer the question
In order to leave comments, you need to log in
Well, you can "head on" - calculate the age as datediff(year, BirthDate, getdate())
or even cluster it by age groups right away.
That is something like:
SELECT
LoginID,
age_group = datediff(year, BirthDate, getdate()) -- или же кэйсом разбивать на интервалы
FROM HumanResources.Employee
where age_group between 25 and 30
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question