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