Professional Documents
Culture Documents
Joins
Joins
========================
REQUIREMENT:
============
From above database table data, you are requested to write queries / solutions for
below asks:
1. Write the SQL to produce the following report on the vital signs data.
Order by patient number and visit number.
PatientNo VisitNo VisitDate Systolic
Diastolic
-------------select
PATIENTS.Patientno,VISITS.Visitno,VISITS.VisitDate,VITALSIGNS.Systolic,VITALSIGNS.D
iastolic from PATIENTS Inner Join VISITS on PATIENTS.PatientId=VISITS.PatientID
2. List the patient number and initials for every patient that never had a headache
3.Produce the following report, showing each adverse event and the details of the
medication taken for that adverse event. Include all adverse events, even those for
which no medication was taken.
PatientNo AE Med
MedDate
-------------select
PATIENTS.Patientno,VISITS.PatientId,ADVERSEEVENTS.*,MEDS.MedDate from PATIENTS
Inner Join VISITS on PATIENTS.PATIENTID=VISITS.PATIENTID
4.List the distinct set of medications taken in the study. Beware � this is not as
trivial as it looks. Extra credit for being careful.
5.List the average systolic blood pressure (Sys) for all patients who ever had an
adverse event of �High BP�
-------------select
PATIENTS.Patientid,PATIENTS.PatientNo,PATIENTS.Initials,count(VISITS.PatientId)
from PATIENTS Inner Join VISITS on PATIENTS.PatientId=VISITS.PatientId
Inner Join ADVERSEEVENTS on VISITS.VisitId=ADVERSEEVENTS.VisitId and
ADVERSEEVENTS.AE = 'Headache' group by
PATIENTS.Patientid,PATIENTS.PatientNo,PATIENTS.Initials
having count(VISITS.PatientId)>1;