在SQL中查找重復(fù)字段的方法有幾種:
SELECT field, COUNT(*)
FROM table_name
GROUP BY field
HAVING COUNT(*) > 1;
SELECT field
FROM table_name
WHERE (SELECT COUNT(*) FROM table_name t2 WHERE t2.field = table_name.field) > 1;
SELECT field
FROM (
SELECT field, ROW_NUMBER() OVER (PARTITION BY field ORDER BY field) AS row_num
FROM table_name
) AS subquery
WHERE row_num > 1;