I have a table called person, which has fields person number, name and age. I want a query which retrieves person details according to age group. i.e the program should be able to print people in the following age groups separately:
<25 25 - 30 31 -35 >35
This means that the query should be able to select people who are below 25 years and print them alone, followed by those of 25 to 30 years, followed by 32 to 35 years and finally those aged above 35 years from the same query.
how would be the query wriitten or just a snippet of it will do. [ February 10, 2005: Message edited by: Bear Bibeault ]
Vernon, I agree with Paul that this would be better to do in Java, or whatever language you are doing the processing in. For example, if the whole program resides on the database, you could use a stored procedure.
Ben, I don't think your comment is off topic at all. Storing an age is risky if the data is long lived.
I could be just right to store the age in stead of the birthday! You don't know where he is using it for. Lets say its a survey and he wants to link the answers to the age of the people. In that case it's not sensable at all to store the birthday!
I think Bianca's point is valid: there are some cases where storing the age either makes sense or is the only option. The survey example is a good one. You may not have even asked for the birthdate, or you may not know when the survey was taken, but you must know the age of the respondent at the time of the survey -- not on any future date.
Clearly, if you need to be able to calculate a person's age at any time, you'll need their birthdate.
Even if you don't have the exact date, I still think you are better off storing a year of birth (granted, you could be off by a year.) Or, you could store the age and the date that age was entered. Just storing the age yields out of date information very quickly. In just one year a 24 year old switches ages groups in the given example.