数据库
首页 > 数据库> > 数据库多字段去重

数据库多字段去重

作者:互联网

# 查询

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
	)

  

标签:payout,realname,get,数据库,time,shopee,多字,SELECT
来源: https://www.cnblogs.com/xiaowangba9494/p/15670402.html