count the number of times that patient 1862 was prescribed pantoprazole until 2 years ago.
select count(*) from prescriptions where prescriptions.hadm_id in ( select admissions.hadm_id from admissions where admissions.subject_id = 1862 ) and prescriptions.drug = 'pantoprazole' and datetime(prescriptions.startdate) <= datetime(current_time,'-2 year')