删除表中重复的记录,相同数据只保留其中一条

删除developer_report_detail 表中customer_id、cloud_service_type_code、month重复的记录,只保留其中一条。

DELETE 
FROM
	developer_report_detail d 
WHERE
	EXISTS (
	SELECT
		1 
	FROM
		(
		SELECT
			customer_id,
			cloud_service_type_code,
			`month`,
			max( id ) AS maxId,
			COUNT( 1 ) c 
		FROM
			developer_report_detail 
		GROUP BY
			customer_id,
			cloud_service_type_code,
			`month` 
		HAVING
			c > 1 
		) tmp 
	WHERE
		d.customer_id = tmp.customer_id 
		AND d.cloud_service_type_code = tmp.cloud_service_type_code 
		AND d.MONTH = tmp.`month` 
	AND d.id != tmp.maxid 
	);