需求:
FLowKind表,里有四个字段:Id,KindEngName,Casnumber,Classifications
里面这三个字段KindEngName,Casnumber,Classifications一样的数据会出现多条.
需求是:保留这三个字段KindEngName,Casnumber,Classifications相同数据,其中的一条,其余删除.
with temp as(
select COUNT(1) a,min(id) id,
KindEngName,Casnumber,Classifications from FlowKind
group by KindEngName,Casnumber,Classifications
)
delete from FlowKind where Id in(
select
b.Id dId
from temp
left join FlowKind b
on temp.KindEngName = b.KindEngName and
temp.Casnumber=b.Casnumber and
temp.Classifications = b.Classifications
where temp.a > 1 and b.Id != temp.id)