variable for patient age

For users or potential users.
Post Reply
CCleveland
Posts: 8
Joined: Mon Oct 01, 2007 8:15 am
Location: Missouri

variable for patient age

Post by CCleveland » Tue Feb 26, 2008 11:10 am

I am trying to write a query to sort by patient's age. What is the relevant variable to use.

User avatar
Jorgebon
Posts: 502
Joined: Mon Jun 18, 2007 2:25 pm
Location: Mayaguez, PR
Contact:

Post by Jorgebon » Tue Feb 26, 2008 2:05 pm

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

CCleveland
Posts: 8
Joined: Mon Oct 01, 2007 8:15 am
Location: Missouri

Post by CCleveland » Thu Feb 28, 2008 5:55 am

Jorge,

I am trying to determine the age distribution of my patients, by year. Do you know of a useful how-to guide for SQL queries?

Thanks

User avatar
Jorgebon
Posts: 502
Joined: Mon Jun 18, 2007 2:25 pm
Location: Mayaguez, PR
Contact:

Post by Jorgebon » Thu Feb 28, 2008 11:16 am

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

User avatar
jordansparks
Site Admin
Posts: 5770
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Post by jordansparks » Thu Feb 28, 2008 11:38 am

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.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
Jorgebon
Posts: 502
Joined: Mon Jun 18, 2007 2:25 pm
Location: Mayaguez, PR
Contact:

Post by Jorgebon » Thu Feb 28, 2008 12:09 pm

Hey that's really cool !!
You can then export those numbers as an Excel file and make a graph. That's a little different from what I was thinking, since I was thinking CCleveland wanted a list of patient names.
Jorge Bonilla, DMD

Post Reply