So.. to return the age based on a date type it’s really easy :
SELECT YEAR(CURDATE()) – YEAR(DateofBirth) and we get a result set with the age of the person
But what if I need to search the people with an age range of 60-70 in the table based on their date of birthdays in this format d/m/y ( Ex: 2005-04-11). I considered it was kind of hard because it’s a different thing searching for an certain age if u have only dateofbirths instead of searching through a column where u already have their ages being counted as normal years ( 50, 60 etc )
Another problem that’s not related to the one mentioned above:
Let’s say I have a table with Medics that has their names, surnames and their speciality.
We got 17 specialities : reumatologie, o.r.l, chirurgie etc. and 108 doctors
How do I get the list of the medical specialities and the doctors that are in that range based on this format:
Ex: reumatologie – 4, o.r.l – 5, chirurgie – 10 etc
4 and 5 from the examples are the number of medics. I’ve tried concatenating and all sort of queries none of them worked properly though. Maybe will work with a case? if yes how?
For question 1, you can just do (not very good regarding performance though):
If you want performance, you can add an index on
DateofBirthand use this version: