นับจำนวนผู้ป่วยที่ได้รับการผ่าตัดหลอดเลือดหัวใจตีบตัน-2 ภายใน 2 เดือน หลังจากได้รับการวินิจฉัยว่าเป็นโรคเยื่อหุ้มหัวใจ ไม่จำเป็นต้องใช้ตารางทั้งหมด
count the number of patients who had a coronar arteriogr-2 cath procedure performed within 2 months after being diagnosed with pericardial disease nos.It is not neccessary to use all the tables.
 cost:  row_id [ number]  subject_id [ number]  hadm_id [ number]  event_type [ text]  event_id [ number]  chargetime [ time]  cost [ number] 
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 = 'pericardial disease nos')) AS t1 JOIN (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 = 'coronar arteriogr-2 cath')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND DATETIME(t2.charttime) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month')