Enrollment in some programs (ELL, Special Education, Learning Center) is tracked through the spenrollments table. The following programid values are relevant:
To pull most recent record for a program (LC in this example)
WITH --get latest LC record maxdates_lc AS ( SELECT studentid, MAX(enter_date) latest_date FROM spenrollments WHERE programid = 6213 GROUP BY studentid ), --pull only records from a certain date lclist AS ( SELECT studentid, 1 AS lc FROM maxdates_lc WHERE latest_date >= to_date('2012-08-01', 'YYYY-MM-DD') )