No need to regenerate Course:

Lesson Remind Date:3

Monthly Remind Date:20

17

Get SQL:select stid, sum(cnt) as cnt, course from hb_course_std cs join hb_course c on concat(c.coursecode,'|cou') = cs.course join (select count(*) as cnt, csid from hb_lesson_std where lessondt > '2026-06-17' group by csid) ls on ls.csid = cs.csid where enddt > '2026-06-17' and coursetype = 'regularL' group by stid, course