นับจำนวนผู้ป่วยที่ได้รับยาไนโตรกลีเซอรีนภายในเดือนเดียวกันหลังจากขั้นตอนการตรวจเลือดผ่านพอร์ทัลในหนึ่งปีก่อนหน้า ไม่จำเป็นที่จะต้องใช้ตารางทั้งหมด
count the number of patients who were prescribed nitroglycerin within the same month following a portal contr phlebogram procedure in a year before.It is not neccessary to use all the tables.
 prescriptions:  row_id [ number]  subject_id [ number]  hadm_id [ number]  startdate [ time]  enddate [ time]  drug [ text]  dose_val_rx [ text]  dose_unit_rx [ text]  route [ text] 
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, procedures_icd.charttime FROM procedures_icd JOIN admissions ON procedures_icd.hadm_id = admissions.hadm_id WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'portal contr phlebogram') AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'nitroglycerin' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t1.charttime, 'start of month') = DATETIME(t2.startdate, 'start of month')