/* 清理组织人员的历史数据 */
/* 清理3个月以上的旧数据 */
delete from t_sec_user_h where FCREATETIME <= {ts'2020-09-01 00:00:00'};
/* 每天每个人员只保留最新的历史数据 */
delete from t_sec_user_h where fid not in ( select t.fid from (select max(fid) fid from t_sec_user_h group by fuserid, fenddate) t);
delete from t_sec_user_h_l where fid not in (SELECT fid from t_sec_user_h);
DELETE from t_sec_user_h_u where fid not in (SELECT fid from t_sec_user_h);
DELETE from t_sec_userposition_h where fid not in (SELECT fid from t_sec_user_h);
DELETE from t_sec_userposition_h_l where fentryid not in (SELECT fentryid from t_sec_userposition_h);

/* 清理3个月以上的旧数据 */
delete from t_org_org_h where FCREATETIME <= {ts'2020-09-01 00:00:00'};
/* 每天每个组织只保留最新的历史数据 */
delete from t_org_org_h where fid not in ( select t.fid from (select max(fid) fid from t_org_org_h group by forgid, fenddate) t);
DELETE from t_org_org_h_l where FID not in (SELECT FID from t_org_org_h);
delete from t_org_structure_h where FCREATETIME <= {ts'2020-09-01 00:00:00'};
DELETE from t_org_structure_h where forgid not in (SELECT forgid from t_org_org_h);
DELETE from t_org_structure_h_l where FID not in (SELECT FID from t_org_structure_h);
