去重sql ,修改表名:ap_jyz_jyzqgdwa即可

SELECT
	*
FROM
	(
		SELECT
			*, row_number () over (PARTITION BY id ORDER BY id DESC) AS rk
		FROM
			ap_jyz_jyzqgdwa
	) tmp
WHERE
	tmp.rk < 2

查看已去重之后id分组数量

SELECT
	a.id,
	count(1)
FROM
	(
		SELECT
			*
		FROM
			(
				SELECT
					*, row_number () over (PARTITION BY id ORDER BY id DESC) AS rk
				FROM
					ap_jyz_jyzqgdwa
			) tmp
		WHERE
			tmp.rk < 2
	) a
GROUP BY
	a.id

查看已去重之后的数据条数

SELECT
	COUNT(1)
FROM
	(
		SELECT
			*
		FROM
			(
				SELECT
					*, row_number () over (PARTITION BY id ORDER BY id DESC) AS rk
				FROM
					ap_jyz_jyzqgdwa
			) tmp
		WHERE
			tmp.rk < 2
	) a

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐