SQL Server獲取重復(fù)數(shù)據(jù)的方法
一 獲取重復(fù)的數(shù)據(jù)的值
select user_name from users
group by user_name
having(count(1)>1)
二 獲取重復(fù)數(shù)據(jù)的記錄
select * from users where user_name in
(
select user_name from users
group by user_name
having(count(1)>1)
)
三 獲取多余的重復(fù)數(shù)據(jù)
select * from users where user_name not in
(
select max(user_name) from users
group by user_name
having(count(1)>1)
)
一 獲取重復(fù)的數(shù)據(jù)的值
select user_name from users
group by user_name
having(count(1)>1)
二 獲取重復(fù)數(shù)據(jù)的記錄
select * from users where user_name in
(
select user_name from users
group by user_name
having(count(1)>1)
)
三 獲取多余的重復(fù)數(shù)據(jù)
select * from users where user_name not in
(
select max(user_name) from users
group by user_name
having(count(1)>1)
)