BEGIN;
INSERT INTO official_withdrawals_summary
	SELECT mem_no, med_no, course_no, mp, count(*), ins_ts::date as ins_date FROM official_withdrawals
	WHERE ins_ts::date <= 'YESTERDAY'
	GROUP BY mem_no, med_no, course_no, mp, ins_date
	ORDER BY ins_date;
DELETE FROM official_withdrawals WHERE ins_ts::date <= 'YESTERDAY';
COMMIT;