SQL筛选重复数据的方法有多种,下面列举了几种常用的方法:
SELECT column1, column2, COUNT(*) as count
FROM table
GROUP BY column1, column2
HAVING COUNT(*) > 1;
SELECT column1, column2
FROM table
WHERE column2 IN (
SELECT column2
FROM table
GROUP BY column2
HAVING COUNT(*) > 1
);
WITH cte AS (
SELECT column1, column2, ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY column1) AS rn
FROM table
)
SELECT column1, column2
FROM cte
WHERE rn > 1;
以上是几种常用的方法,根据具体情况选择合适的方法进行筛选。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 在哪些场景下sql average最有用