นับจำนวนผู้ป่วยที่ได้รับการวินิจฉัยว่าเป็นภาวะหัวใจห้องบนแต่ไม่ได้กลับมาโรงพยาบาลในเดือนเดียวกันตั้งแต่ 3 ปีที่แล้ว ไม่จำเป็นต้องใช้ตารางทั้งหมด
count the number of patients that have been diagnosed with atrial fibrillation but did not return to the hospital during the same month since 3 years ago.It is not neccessary to use all the tables.
 lab:  labid [ number]  patientunitstayid [ number]  labname [ text]  labresult [ number]  labresulttime [ time] 
SELECT (SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'atrial fibrillation' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t1) - (SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'atrial fibrillation' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid WHERE t2.diagnosistime < patient.hospitaladmittime AND DATETIME(patient.hospitaladmittime) >= DATETIME(CURRENT_TIME(), '-3 year') AND DATETIME(t2.diagnosistime, 'start of month') = DATETIME(patient.hospitaladmittime, 'start of month'))