数据库多字段去重

# 查询

SELECT
	*
FROM
	shopee_finance_data_statistics_v2 a
WHERE
	(
		a.get_time,
		a.realname,
		a.payout_time
	) IN (
		SELECT
			get_time,
			realname,
			payout_time
		FROM
			shopee_finance_data_statistics_v2
		GROUP BY
			get_time,
			realname,
			payout_time
		HAVING
			count(*) > 1)

  

 

# 删除

DELETE
FROM
	shopee_finance_data_statistics_v2
WHERE
	id IN (
		SELECT
			id
		FROM
			(
				SELECT
					id
				FROM
					shopee_finance_data_statistics_v2 a
				WHERE
					(
						a.get_time,
						a.realname,
						a.payout_time
					) IN (
						SELECT
							get_time,
							realname,
							payout_time
						FROM
							shopee_finance_data_statistics_v2
						GROUP BY
							get_time,
							realname,
							payout_time
						HAVING
							count(*) > 1
					)
				AND id NOT IN (
					SELECT
						min(id)
					FROM
						shopee_finance_data_statistics_v2
					GROUP BY
						get_time,
						realname,
						payout_time
					HAVING
						count(*) > 1
				)
			) AS tmptb
	)

  

上一篇:Explain 工具


下一篇:Shopee首公里怎么用,有什么优势