นับจำนวนผู้ที่ได้รับการสั่งจ่ายยาภายใน 2 เดือน ภายหลังการวินิจฉัยประวัติการล้มตั้งแต่ 4 ปีที่แล้ว ไม่จำเป็นต้องใช้ตารางทั้งหมด
count the number of people who were prescribed lr within 2 months following a diagnosis of personal history of fall since 4 years ago.It is not neccessary to use all the tables.
 d_items:  row_id [ number]  itemid [ number]  label [ text]  linksto [ text] 
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, diagnoses_icd.charttime FROM diagnoses_icd JOIN admissions ON diagnoses_icd.hadm_id = admissions.hadm_id WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'personal history of fall') AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'lr' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month')