------------------------------------------------------
-- 중복 데이터 조회
------------------------------------------------------
SELECT *
FROM (
SELECT some_id
, ROW_NUMBER() OVER (
PARTITION BY some_id ORDER BY some_id ) as dup_idx
FROM tbl_some_table (NOLOCK)
) tb_dup
WHERE tb_dup.dup_idx > 1;
------------------------------------------------------
-- 중복 데이터 기준으로 중복된 데이터를 다 조회
------------------------------------------------------
SELECT t.*
FROM (
SELECT some_id
, ROW_NUMBER() OVER (
PARTITION BY some_id ORDER BY some_id ) as dup_idx
FROM tbl_some_table (NOLOCK)
) tb_dup INNER JOIN tbl_some_table t (NOLOCK)
ON t.some_id = tb_dup.some_id
WHERE tb_dup.dup_idx > 1;
------------------------------------------------------
-- 중복 데이터 삭제
------------------------------------------------------
DELETE tb_dup
FROM (
SELECT some_id
, ROW_NUMBER() OVER (
PARTITION BY some_id ORDER BY some_id ) as dup_idx
FROM tbl_some_table
) tb_dup
WHERE tb_dup.dup_idx > 1;
------------------------------------------------------
-- 여러 컬럼일 경우 중복 데이터 삭제
------------------------------------------------------
DELETE tb_dup
FROM (
SELECT some_id, some_nm, some_description
, ROW_NUMBER() OVER (
PARTITION BY some_id, some_nm, some_description
ORDER BY some_id, some_nm, some_description ) as dup_idx
FROM tbl_some_table
) tb_dup
WHERE tb_dup.dup_idx > 1;
댓글 없음:
댓글 쓰기