variable for patient age
-
- Posts: 8
- Joined: Mon Oct 01, 2007 8:15 am
- Location: Missouri
variable for patient age
I am trying to write a query to sort by patient's age. What is the relevant variable to use.
The patient's age is probably the result of a calculation based on the patient's birth date. You can find that in the Patient table. If you tell us what you would like we can probably help you write the query. This is the simplest way to sort by age:
select * from patient
Order by birthdate
Jorge Bonilla, DMD
select * from patient
Order by birthdate
Jorge Bonilla, DMD
-
- Posts: 8
- Joined: Mon Oct 01, 2007 8:15 am
- Location: Missouri
I like "Teach Yourself SQL in Ten Minutes" by Ben Forta. I got it at Border's. So what you want could be something like a total number of patients within a range. For example, a list and total number of patients under the age of ten. I think the way to keep it simple is to have one query for each age range. Let me see if I can come up with something.
Jorge Bonilla, DMD
Jorge Bonilla, DMD
- jordansparks
- Site Admin
- Posts: 5770
- Joined: Sun Jun 17, 2007 3:59 pm
- Location: Salem, Oregon
- Contact:
I threw this query together.
SELECT YEAR(CURDATE())-YEAR(BirthDate) Age,COUNT(*) FROM patient
WHERE BirthDate>'1800'
AND BirthDate <= CURDATE()
AND PatStatus !=4
GROUP BY Age
It works really well, but it doesn't take into account the month or day a patient was born, just the year they were born. That's probably close enough, though.
SELECT YEAR(CURDATE())-YEAR(BirthDate) Age,COUNT(*) FROM patient
WHERE BirthDate>'1800'
AND BirthDate <= CURDATE()
AND PatStatus !=4
GROUP BY Age
It works really well, but it doesn't take into account the month or day a patient was born, just the year they were born. That's probably close enough, though.
Jordan Sparks, DMD
http://www.opendental.com
http://www.opendental.com