22,301
社区成员




delete ta from 表 ta where not exists(select 1 from 表 tb where ta.tyear=tb.tyear and ta.tmonth= tb.tmonth
and ta.companyid=tb.companyid and ta.id<tb.id)
delete 表
from
(
select companyid,tyear,tmonth,min(id) as id
from 表
group by companyid,tyear,tmonth
)t
where t.companyid=表.companyid and t.tyear =表.tyear and t.tmonth = 表.tmonth
and t.id < 表.id
;with t
as
(
select *,
ROW_NUMBER() over(partition by companyid,tyear,tmonth order by id) as rownum
from 表
)
delete from t
where rownum > 1
;with t
as
(
select *,
ROW_NUMBER() over(order by companyid,tyear,tmonth order by id) as rownum
from 表
)
delete from t
where rownum > 1