SQL數據去重的方法有以下幾種:
例如:SELECT DISTINCT column1, column2 FROM table_name;
例如:SELECT column1, column2 FROM table_name GROUP BY column1, column2 HAVING COUNT(*) = 1;
例如:
WITH CTE AS (
SELECT column1, column2, ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY column1, column2) AS rn
FROM table_name
)
SELECT column1, column2
FROM CTE
WHERE rn = 1;
例如:
SELECT column1, column2
FROM table_name t1
WHERE NOT EXISTS (
SELECT 1
FROM table_name t2
WHERE t1.column1 = t2.column1
AND t1.column2 = t2.column2
AND t1.id != t2.id
);
以上是SQL數據去重的幾種常用方法,可以根據具體情況選擇適合的方法來去除重復數據。