นับจำนวนยาที่สั่งจ่ายให้ผู้ป่วย 002-77945 จนถึง 3 ปีที่แล้ว ไม่จำเป็นต้องใช้ตารางทั้งหมด
count the number of drugs that have been prescribed patient 002-77945 until 3 years ago.It is not neccessary to use all the tables.
 patient:  uniquepid [ text]  patienthealthsystemstayid [ number]  patientunitstayid [ number]  gender [ text]  age [ text]  ethnicity [ text]  hospitalid [ number]  wardid [ number]  admissionheight [ number]  admissionweight [ number]  dischargeweight [ number]  hospitaladmittime [ time]  hospitaladmitsource [ text]  unitadmittime [ time]  unitdischargetime [ time]  hospitaldischargetime [ time]  hospitaldischargestatus [ text] 
SELECT COUNT(*) FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-77945')) AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-3 year')