#1.删除t_discredit_company_info表重复数据(t_discredit_company_info表数据重复)
DELETE FROM t_discredit_company_info WHERE id IN (
SELECT * FROM (
SELECT id FROM t_discredit_company_info WHERE (company_id,attribute_year_month)
IN ( SELECT company_id,attribute_year_month FROM t_discredit_company_info GROUP BY company_id,attribute_year_month HAVING COUNT(1) > 1
) AND id NOT IN (
-- 查询最小id的记录
SELECT MIN(id) FROM t_discredit_company_info GROUP BY company_id,attribute_year_month HAVING COUNT(1) > 1
)) AS stu_repeat_copy );
#2.查询t_discredit_company表比t_discredit_company_info表多了哪些数据(t_discredit_company表数据多,t_discredit_company_info表数据少)
SELECT count(*) FROM t_discredit_company o LEFT JOIN t_discredit_company_info w ON o.company_id=w.company_id
WHERE w.company_id IS NULL;
#3.删除t_discredit_company表的多余数据(t_discredit_company表数据多,t_discredit_company_info表数据少)
delete from t_discredit_company where t_discredit_company.company_id not in
(select company_id from t_discredit_company_info);