我写了如下语句
delete from stab as A
from A.cl1,A.cl2
in (select cl1,cl2 from stb group by cl1,cl2 having count(*) > 1)
and rowid not in (select min(rowid) from stab group by cl1,cl2 having count(*)>1)
delete from stab where rowid not in
(select min(rowid) from stab
group by cl1,cl2
having count(*)>1)
这样直接写就可以了
#2
这里rowid可以改成别的只要是不重复的属性就可以
#3
delete stab from stab t1 inner join ( select *,row_number() over(partition by cl1,cl2 order by cl1) as row from stab ) t2 on t1.cl1 = t2.cl1 and t1.cl2 = t2.cl2
with t1 as ( select *,row_number() over(partition by cl1,cl2 order by cl1) as row from stab )
delete t1 from t1 inner join t1 as t2 on t1.cl1 = t2.cl1 and t1.cl2 = t2.cl2 and t1.row = t2.row
where t2.row >=2
#7
row_number() 不是被怎么破
#8
sqlserver2008 row_number()不识别,怎么破
#1
delete from stab where rowid not in
(select min(rowid) from stab
group by cl1,cl2
having count(*)>1)
这样直接写就可以了
#2
delete from stab where rowid not in
(select min(rowid) from stab
group by cl1,cl2
having count(*)>1)
这样直接写就可以了
这里rowid可以改成别的只要是不重复的属性就可以
#3
delete stab from stab t1 inner join ( select *,row_number() over(partition by cl1,cl2 order by cl1) as row from stab ) t2 on t1.cl1 = t2.cl1 and t1.cl2 = t2.cl2
我写了如下语句
delete from stab as A
from A.cl1,A.cl2
in (select cl1,cl2 from stb group by cl1,cl2 having count(*) > 1)
and rowid not in (select min(rowid) from stab group by cl1,cl2 having count(*)>1)
delete stab from stab t1 inner join ( select *,row_number() over(partition by cl1,cl2 order by cl1) as row from stab ) t2 on t1.cl1 = t2.cl1 and t1.cl2 = t2.cl2
我写了如下语句
delete from stab as A
from A.cl1,A.cl2
in (select cl1,cl2 from stb group by cl1,cl2 having count(*) > 1)
and rowid not in (select min(rowid) from stab group by cl1,cl2 having count(*)>1)
delete stab from stab t1 inner join ( select *,row_number() over(partition by cl1,cl2 order by cl1) as row from stab ) t2 on t1.cl1 = t2.cl1 and t1.cl2 = t2.cl2