Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
acutshall
Starting Member
1 Post |
Posted - 2007-06-18 : 14:15:34
|
I'm working with multiple variations of patient data. A patient may have multiple registrations each with a different patient number (but all tied together with the same patient ID). What I'm trying to determine is the most frequent date of birth (DOB) for any given patient. In case of a draw, I will take the one with the latest activity date. If someone could help me construct a SQL query to determine this on a given set of patients, I would be most appreciative because I'm already behind the proverbial .The table in question would look something like this:tbPatientVariations-------------------PatientID intPatientNbr varchar(16)PatientName varchar(64)PatientDOB datetimeThanks for all of your help,Aaron N. CutshallBusiness Systems AnalystIndiana Health Information Exchange846 N. Senate Av., Suite 300Indianapolis, IN 46202-4121Direct: 317-644-1742Main: 317-644-1750Fax: 317-644-1751 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-06-18 : 14:21:45
|
| select patientid, patientdobfrom tbPatientVariationsgroup by patientid, patientdoborder by patientidsince there is no column for activitydate, this is the nearest I can provide.Peter LarssonHelsingborg, Sweden |
 |
|
|
phdiwakar
Starting Member
15 Posts |
Posted - 2007-06-18 : 14:57:58
|
| Aaron,Expanding on Peso's query, this one gives you the frequency of each DOB for a patient:select patientid, patientdob, count(*) as Frequency from tbPatientVariationsgroup by patientid, patientdob order by patientidAfter that you can use Row_number or rank over to get the most frequent row for each patientid. To give you the exact solution, we need some DDL table creation statements and insert statements with the data.( Also for the Latest acitivity date's table) |
 |
|
|
|
|
|
|
|